A good answer might be:
Here is what a switch statement looks like:
switch ( integerExpression )
case label1 :
case label2 :
case label3 :
. . . other cases like the above
Here is how it works:
- Only one case will be selected per execution of the
- The value of
integerExpression determines which case is selected.
integerExpression must evaluate to an
label must be an integer literal (like 0, 23, or 'A'), but not
an expression or variable.
- There can be any number of statements in a
statementList is usually followed with
- Each time the
switch statement is executed, the following happens:
integerExpression is evaluated.
labels after each
case are inspected one by one,
starting with the first.
- The first label that matches has its
- The statements execute until the
break statement is encountered.
- Now the entire
switch statement is complete.
- If no case label matches the value of
default case is picked, and its statements execute.
Would you believe that there are even more rules for the break-statement?