The switch statement is a mechanism by which you can test a given scalar variable against a set of discrete values. If you have an integer variable that you want to test against a limited set of constant values, you have two choices:
A series of if statements.
A multipart switch statement.
The key points to note are that the switch statement is available only when you’re testing for integer values, and you can only test for equality against a constant value. You cannot test for a variance (between one value and another), nor can you test floating-point values. The final restriction is that you cannot use a variable as a value to test against.
The generic syntax for the switch statement emulates multiple if/else if statements ...