Syntax of switch Statement in C++
switch (expression) { case value_1: // statements_1; break; case value_2: // statements_2; break; ..... ..... default: // default_statements; break; }
The following example demonstrate how to use the switch statement syntax in C++.
Switch Statement in C++
The C++ Switch case statement evaluates a given expression and based on the evaluated value(matching a certain condition), it executes the statements associated with it. It is an alternative to the long if-else-if ladder which provides an easy way to dispatch execution to different parts of code based on the value of the expression.