SwitchStatement ::= ‘switch’ S? ‘(‘ S? Expression S? ‘)’ S? BracedStatements
The “switch” statement indicates the start of “switched”
conditional statement execution. The expression
is evaluated (must evaluate to char, short,
or long type) and compared against the case labels
within the braced statements.
CaseLabel ::= ‘case’ S Constant S? ‘:’
A case label is composed of the text “case,”
a constant, and a colon. If
the constant matches the “switched” conditional expression, this
is the label to which script execution jumps. Duplicate constants
are not permitted within a single “switch” statement.
Case labels are only valid in the immediate context of a switched control
block. An error occurs if the statement appears in any other
context.
DefaultLabel ::= ‘default’ S? ‘:’
A default case label is composed of the text “default”
and a colon. If the “switched” conditional
expression does not match any other case label, this is the label
to which script execution jumps. Only a single “default”
statement is permitted within a single “switch” statement.
A default case label is only valid in the immediate context of a switched
control block. An error occurs if the statement appears in
any other context.
See also: [Evaluation and null
statements] [The "goto" statement and text labels]
[The "return" statement] [The
"if" and "else" statements]
[The "for" statement] [The
"while" statement] [The "do" statement] [The
"switch," "case," and "default" statements]
[The "break" statement] [The
"continue" statement] [Opcode and mod byte
escape sequences]
|