CHAPTER 14: Blocks and Statements Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

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 statement labels are used with break (S14.13) or continue (S14.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 identifier as a local variable or as the parameter of an exception handler (S14.18) does not hide a statement label with the same name.

A labeled statement is executed by executing the immediately contained Statement. If the statement is labeled by an Identifier and the contained Statement completes abruptly because of a break with the same Identifier, then the labeled statement completes normally. In all other cases of abrupt completion of the Statement, the labeled statement completes abruptly for the same reason.

Top© 1996 Sun Microsystems, Inc. All rights reserved.