0
|
10857 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

# Mathematica For Loop with multiple iterators?

Posted 11 years ago
 I'm kinda new to using Mathematica, so any help is appreciated.Is it possible in Mathematica to use multiple iterators in for loops?   Something like For[i=1, j=1, i<1, j<3, i++, j++, ] and so on?  I'm getting an error on this,  is there a different way to write this sort of syntax in Mathematica?  Thanks!
2 Replies
Sort By:
Posted 11 years ago
 What is it that you want to archive? For loops can usually (and should) be avoided, since there are better constructs.In your example, it looks like i and j always have the same value, so one of them is redunant. If this is not the intention, but you want all pairs of combinations,then you can use Do:Do[    code,{i,1,3},{j,1,2}];
Posted 11 years ago
 You can try something like this:For[(i = 1; j = 1),    i < 3 && j < 3,    (i++; j++)]I.e., use compound espressions and the And operator (the &&).  (Note that I changed your i<1 to i<3 so something would actually happen.) But, as many in this group will suggest, you really should take some time to learn about the different programming approaches in Mathematica so that you move away from the procedural approach of using things like For  and Do loops.  You can get a taste here:http://www.wolfram.com/broadcast/video.php?channel=89&video=409and begin to get launched into learning things here:http://reference.wolfram.com/mathematica/guide/CoreLanguageOverview.html
Community posts can be styled and formatted using the Markdown syntax.