Next: , Previous: , Up: Loop Statements   [Contents][Index]

19.6.4 for Statement

A for statement uses three expressions written inside a parenthetical group to define the repetition of the loop. The first expression says how to prepare to start the loop. The second says how to test, before each iteration, whether to continue looping. The third says how to advance, at the end of an iteration, for the next iteration. All together, it looks like this:

for (start; continue-test; advance)

The first thing the for statement does is compute start. The next thing it does is compute the expression continue-test. If that expression is false (zero), the for statement finishes immediately, so body is executed zero times.

However, if continue-test is true (nonzero), the for statement executes body, then advance. Then it loops back to the not-quite-top to test continue-test again. But it does not compute start again.