[stmt.for] (original) (raw)

8 Statements [stmt.stmt]

8.6 Iteration statements [stmt.iter]

8.6.4 The for statement [stmt.for]

The for statement

is equivalent to

except that names declared in the init-statement are in the same declarative region as those declared in thecondition, and except that acontinue in statement (not enclosed in another iteration statement) will execute expression before re-evaluating condition.

[Note 1:

Thus the first statement specifies initialization for the loop; the condition ([stmt.select]) specifies a test, sequenced before each iteration, such that the loop is exited when the condition becomesfalse; the expression often specifies incrementing that is sequenced after each iteration.

— _end note_]

A missing conditionmakes the implied while clause equivalent to while(true).

If the init-statement is a declaration, the scope of the name(s) declared extends to the end of the for statement.

[Example 1: int i = 42;int a[10];for (int i = 0; i < 10; i++) a[i] = i;int j = i; — _end example_]