Skip to main content

Timeline for How do I write nested for-loops?

Current License: CC BY-SA 3.0

10 events
when toggle format what by license comment
Jan 22, 2015 at 6:45 comment added Sjoerd C. de Vries @Szabolcs not entirely true. For instance, a set of assignments without ; at the end but separated by line breaks in a single cell execute fine whereas the same lines in a module or loop or so will cause problems.
Jan 22, 2015 at 2:55 history edited m_goldberg CC BY-SA 3.0
Routine clean-up
Jan 22, 2015 at 0:33 review Close votes
Jan 22, 2015 at 7:16
Jan 22, 2015 at 0:11 comment added Daniel Lichtblau Did you even try anything? For[i = 1, i <= 3, i++, For[j = i^2, j <= i^2 + 3, j++, Print["{i,j}=", {i, j}] ] ]
Jan 21, 2015 at 18:30 comment added Szabolcs @user6818 "lines" have no meaning in Mathematica. Line breaks don't matter at all, just like in C, Java, etc. The documentation page of For has several examples with multipe commands in the body of For. So does the documentation page of Do. Whether or not you write them on a single line or you break them across multiple ones makes no difference.
Jan 21, 2015 at 18:28 comment added Szabolcs @user6818 Just use ; to separate commands, as usual. For[i=0, i < 10, i++, Print[i]; Print[i^2]]. Pay attention to the difference between , and ;. But please do not use For if you are a beginner in Mathematica ... take a look at Do instead and try to use functional constructs such as Table, Map, etc. whenever possible.
Jan 21, 2015 at 18:16 answer added Dr. belisarius timeline score: 5
Jan 21, 2015 at 17:31 comment added user6818 @YvesKlett Can you show an example of how to write multiple lines in a "call" on Mathematica? All the examples on reference.wolfram are single line examples and its not clear how something like the above can be achieved via that!
Jan 21, 2015 at 17:27 comment added Yves Klett You can nest any amount of Do or For calls... so, yes, doable. Please take a look at the documentation for details.
Jan 21, 2015 at 17:15 history asked user6818 CC BY-SA 3.0