Switch Statement

The switch statement consists of a series of case labels, an optional default case and
statements to execute for each case

Recall that there are two selection, or branch, structures in C++. The first selection
structure, which is implemented with if and if…else statements, usually requires
the evaluation of a (logical) expression. The second selection structure, which does
not require the evaluation of a logical expression, is called the switch structure.
C++’s switch structure gives the computer the power to choose from among many
alternatives

In C++, switch, case, break, and default are reserved words. In a switch
structure, first the expression is evaluated. The value of the expression is then
used to perform the actions specified in the statements that follow the reserved
word case. Recall that in a syntax, shading indicates an optional part of the
definition.
Although it need not be, the expression is usually an identifier. Whether it is an
identifier or an expression, the value can be only integral. The expression is
sometimes called the selector. Its value determines which statement is selected for
execution. A particular case value should appear only once. One or more statements
may follow a case label, so you do not need to use braces to turn multiple
statements into a single compound statement. The break statement may or may
not appear after each statement

The 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 statement 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