10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

BLOCKS AND STATEMENTS <strong>The</strong> basic for Statement 14.14.1<br />

14.14.1.1 Initialization of for statement<br />

A for statement is executed by first executing the ForInit code:<br />

• If the ForInit code is a list of statement expressions (§14.8), the expressions<br />

are evaluated in sequence from left to right; their values, if any, are discarded.<br />

If evaluation of any expression completes abruptly for some reason, the for<br />

statement completes abruptly for the same reason; any ForInit statement<br />

expressions to the right of the one that completed abruptly are not evaluated.<br />

If the ForInit code is a local variable declaration, it is executed as if it were a<br />

local variable declaration statement (§14.4) appearing in a block. <strong>The</strong> scope of a<br />

local variable declared in the ForInit part of a basic for statement (§14.14)<br />

includes all of the following:<br />

• Its own initializer<br />

• Any further declarators to the right in the ForInit part of the for statement<br />

• <strong>The</strong> Expression and ForUpdate parts of the for statement<br />

• <strong>The</strong> contained Statement<br />

If execution of the local variable declaration completes abruptly for any reason,<br />

the for statement completes abruptly for the same reason.<br />

• If the ForInit part is not present, no action is taken.<br />

14.14.1.2 Iteration of for statement<br />

Next, a for iteration step is performed, as follows:<br />

• If the Expression is present, it is evaluated. If the result is of type Boolean, it<br />

is subject to unboxing conversion (§5.1.8). If evaluation of the Expression or<br />

the subsequent unboxing conversion (if any) completes abruptly, the for<br />

statement completes abruptly for the same reason. Otherwise, there is then a<br />

choice based on the presence or absence of the Expression and the resulting<br />

value if the Expression is present:<br />

DRAFT<br />

◆ If the Expression is not present, or it is present and the value resulting from<br />

its evaluation (including any possible unboxing) is true, then the contained<br />

Statement is executed. <strong>The</strong>n there is a choice:<br />

❖ If execution of the Statement completes normally, then the following two<br />

steps are performed in sequence:<br />

385

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!