Java Reference
In-Depth Information
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList
,
StatementExpression
The
Expression
must have type
boolean
or
Boolean
, or a compile-time error occurs.
The scope and shadowing of a local variable declared in the
ForInit
part of a basic
for
state-
14.14.1.1. Initialization of for Statement
A
for
statement is executed by first executing the
ForInit
code:
• If the
ForInit
code is a list of statement expressions (§
14.8
), 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
state-
ment 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
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.
14.14.1.2. Iteration of for Statement
Next, a
for
iteration step is performed, as follows:
• If the
Expression
is present, it is evaluated. If the result is of type
Boolean
, it is sub-
ject to unboxing conversion (§
5.1.8
).
If evaluation of the
Expression
or the subsequent unboxing conversion (if any)
completes abruptly, the
for
statement completes abruptly for the same reason.
Otherwise, there is then a choice based on the presence or absence of the
Ex-
pression
and the resulting value if the
Expression
is present; see next bullet.
• If the
Expression
is not present, or it is present and the value resulting from its
evaluation (including any possible unboxing) is
true
, then the contained
Statement
is executed. Then there is a choice:
♦ If execution of the
Statement
completes normally, then the following two steps
are performed in sequence: