Files
cppdraft_translate/cppdraft/stmt/for.md
2025-10-25 03:02:53 +03:00

2.3 KiB

[stmt.for]

8 Statements [stmt]

8.6 Iteration statements [stmt.iter]

8.6.4 The for statement [stmt.for]

1

#

The for statement

for ( init-statement conditionopt ; expressionopt ) statement

is equivalent to

{
init-statement
while ( condition ) {
statement
expression ;
}
}

except that the init-statement is in the same scope as the condition, 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.pre]) 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]

2

#

Either or both of the condition and the expression can be omitted.

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