Java Reference
In-Depth Information
expression
case value 1
true
statements1
break
false
.
.
.
false
case value n
true
statementsn
break
false
default
statements
FIGURE 4-5 switch statement
A switch statement executes according to the following rules:
1. When the value of the expression is matched against a case value
(also called a label), the statements execute until either a break state-
ment is found or the end of the switch structure is reached.
2. If the value of the expression does not match any of the case values,
the statements following the default label execute. If the switch
structure has no default label, and if the value of the expression
does not match any of the case values, the entire switch statement is
skipped.
3. A break statement causes an immediate exit from the switch structure.
Search WWH ::




Custom Search