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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BLOCKS AND STATEMENTS Statements 14.5<br />

ContinueStatement<br />

ReturnStatement<br />

SynchronizedStatement<br />

ThrowStatement<br />

TryStatement<br />

StatementNoShortIf:<br />

StatementWithoutTrailingSubstatement<br />

LabeledStatementNoShortIf<br />

If<strong>The</strong>nElseStatementNoShortIf<br />

WhileStatementNoShortIf<br />

ForStatementNoShortIf<br />

<strong>The</strong> following are repeated from §14.9 to make the presentation here clearer:<br />

If<strong>The</strong>nStatement:<br />

if ( Expression ) Statement<br />

If<strong>The</strong>nElseStatement:<br />

if ( Expression ) StatementNoShortIf else Statement<br />

If<strong>The</strong>nElseStatementNoShortIf:<br />

if ( Expression ) StatementNoShortIf else StatementNoShortIf<br />

Statements are thus grammatically divided into two categories: those that<br />

might end in an if statement that has no else clause (a “short if statement”) and<br />

those that definitely do not. Only statements that definitely do not end in a short<br />

if statement may appear as an immediate substatement before the keyword else<br />

in an if statement that does have an else clause.<br />

This simple rule prevents the “dangling else” problem. <strong>The</strong> execution behavior<br />

of a statement with the “no short if” restriction is identical to the execution<br />

behavior of the same kind of statement without the “no short if” restriction; the<br />

distinction is drawn purely to resolve the syntactic difficulty.<br />

DRAFT<br />

369

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

Saved successfully!

Ooh no, something went wrong!