I have little to no understanding of how Mathematica handles scoping, so the question may seem a little bit funny.
What is the preferred way:
Test[] = Module[{},
Do[Print["Hello ", i], {i, 5, 50, 5}];
];
Test[];
Or:
Test[] = Module[{i},
Do[Print["Hello ", i], {i, 5, 50, 5}];
];
Test[];
Table
/Do
/etc. create their own scope for an iterator, and I believe they use textual scoping just likeWith
(but unlikeBlock
andModule
). This may help: reference.wolfram.com/language/guide/ScopingConstructs.html. In particular look at "Learning Resources". $\endgroup$Module[{i=-20}, Do[Print["Hello ", i], {i, 5, 50, 5}]; i]
. Notice that thei
at the end is theModule
variable and is not related to thei
of the loop. $\endgroup$Table
& related functions use the same type of scoping asBlock
(not likeWith
). TryTable[i = 1; Print[i], {i, 5}]
. $\endgroup$i = {4, 5}; Do[Do[ Print[ i ] , {i, i}], {i, i}]
$\endgroup$