Java Reference
In-Depth Information
Statements are thus grammatically divided into two categories: those that might end in an
if statement that has no else clause (a “short if statement”) and those that definitely do not.
Only statements that definitely do not end in a short if statement may appear as an immedi-
ate substatement before the keyword else in an if statement that does have an else clause.
This simple rule prevents the “dangling else ” problem. The execution behavior of a state-
ment with the “no short if ” restriction is identical to the execution behavior of the same
kind of statement without the “no short if ” restriction; the distinction is drawn purely to re-
solve the syntactic difficulty.
14.6. The Empty Statement
An empty statement does nothing.
EmptyStatement:
;
Execution of an empty statement always completes normally.
14.7. Labeled Statements
Statements may have label prefixes.
LabeledStatement:
Identifier : Statement
LabeledStatementNoShortIf:
Identifier : StatementNoShortIf
The Identifier is declared to be the label of the immediately contained Statement .
Unlike C and C++, the Java programming language has no goto statement; identifier state-
ment labels are used with break 14.15 ) or continue 14.16 ) statements appearing anywhere
within the labeled statement.
The scope of a label of a labeled statement is the immediately contained Statement . It is a
compile-time error if the name of a label of a labeled statement (§ 14.7 ) is used within the
scope of the label as a label of another labeled statement.
There is no restriction against using the same identifier as a label and as the name of a pack-
age, class, interface, method, field, parameter, or local variable. Use of an identifier to label
a statement does not obscure (§ 6.4.2 ) a package, class, interface, method, field, paramet-
er, or local variable with the same name. Use of an identifier as a class, interface, method,
Search WWH ::




Custom Search