switch statement chooses between multiple alternatives.
The switch statement compares the value of one expression with multiple constants.
switch( expression ) { case const1: [ statement ] [ break; ] case const2: [ statement ] [ break; ] . . . [default: statement ] }
First, the expression in the switch statement is evaluated.
It must be an integral type.
The result is then compared to the constants, const1, const2, ..., in the case labels.
The constants must be different and can only be integral types including boolean values and character constants.
You can use break to leave the switch statement unconditionally.
The statement is necessary to avoid executing the statements contained in any case labels that follow.