BLOCKS AND STATEMENTS
Labeled Statements
14.6
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 immediate 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 statement 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
resolve the syntactic difficulty.
14.5 The Empty Statement
An
empty statement
does nothing.
EmptyStatement:
;
Execution of an empty statement always completes normally.
14.6 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 language has no
goto
statement; identifier state
ment labels are used with
break
( 14.13) or
continue
( 14.14) statements
appearing anywhere within the labeled statement.
A statement labeled by an identifier must not appear anywhere within another
statement labeled by the same identifier, or a compile time error will occur. Two
statements can be labeled by the same identifier only if neither statement contains
the other.
There is no restriction against using the same identifier as a label and as the
name of a package, class, interface, method, field, parameter, or local variable.
Use of an identifier to label a statement does not hide a package, class, interface,
method, field, parameter, or local variable with the same name. Use of an
271
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved