I think what Szabolcs means is that For is in 99% of the cases used for looping over a variable from a to b (or b to a). Though this can be perfectly done like (something like):
For[i=0,i<10,i++,
body
]
there are several things that go often wrong:
- == instead of =
- <10 or <=10 (does that include 10 or not?) so you might 'miss' one, very common mistake
- I used an 'i' in the example but imagine it is the variable that is a bit longer: loopvar1, then you have to type it 3x, if one of them is wrong, the program will likely break.
- 'i' has to be unique and care must be taken it is not used elsewhere in the code, and I will keep a value afterwards.
This can all be solved using Do (or Table if you want to store each loop)
- no need to type = or ==
- it is immediately obvious what the begin and end is
- variable is only typed once
- variable is local and will be deleted after evaluation, it doesn't stay in memory like 'i' does in the For loop
Overall, the chance of making a mistake is just much smaller. Unless you have a loop that iterates in an unusual way e.g.:
For[i = 1, i < 200, i += i, Print[i]]
or
j = 0;
For[i = 1, i < 200, i += j; j++, Print[i]]
use Do. Like I said, nearly all for loops are used for 'linear sequences', and it is less error-prone than the equivalent Do/Table. Not to mention the execution speed and parallelisation possibilities if one uses Table.