|
|
|
|
|
|
|
Statement4 and continue with Statement5. The break statement causes an immediate exit from the Switch statement. We'll see shortly what happens if we omit the break statements. |
|
|
|
 |
|
 |
|
|
Switch Expression The expression whose value determines which switch label is selected. It cannot be a floating point expression. |
|
|
|
|
|
|
|
|
The syntax template for the Switch statement is |
|
|
|
|
|
|
|
|
IntegralExpression is an expression of integral typechar, short, int, long, or enum (we discuss enum in the next chapter). The optional SwitchLabel in front of a statement is either a case label or a default label: |
|
|
|
|
|
|
|
|
In a case label, ConstantExpression is an integral expression whose operands must be literal or named constants. The following are examples of constant integral expressions (CLASS_SIZE is a named constant of type int): |
|
|
|
|
|
|
|
|
3
CLASS_SIZE
A
2 * CLASS_SIZE + 1 |
|
|
|
|
|