A for loop:
for(INIT; TEST; ADVANCE) { BODY }
Means the following:
INIT; while (true) { if (!TEST) break; BODY; ADVANCE; }
You can write almost any expression for INIT , TEST , ADVANCE and BODY .
Please note that operators and ++ variants are operators with side effects (you should avoid them if you do not use them as i+=1 , etc.):
++i means i+=1; return i i+=1; return ii++ means oldI=i; i+=1; return oldI oldI=i; i+=1; return oldI
Example:
> i=0 > [i++, i, ++i, i, i--, i, --i, i] [0, 1, 2, 2, 2, 1, 0, 0]
ninjagecko Oct 09 '12 at 23:28 2012-10-09 23:28
source share