14.12.1 Initialization
A for
statement is executed by first executing the ForInit code:
- If the ForInit code is a list of statement expressions (§14.7), the expressions are evaluated in sequence from left to right; their values, if any, are discarded. If evaluation of any expression completes abruptly for some reason, the
for
statement completes abruptly for the same reason; any ForInit statement expressions to the right of the one that completed abruptly are not evaluated.
- If the ForInit code is a local variable declaration, it is executed as if it were a local variable declaration statement (§14.3) appearing in a block. In this case, the scope of a declared local variable is its own initializer and any further declarators in the ForInit part, plus the Expression, ForUpdate, and contained Statement of the
for
statement. If execution of the local variable declaration completes abruptly for any reason, the for
statement completes abruptly for the same reason.
- If the ForInit part is not present, no action is taken.