Common form of the switch statement:
The common form of the switch statement is as shown below:
switch switch_expression
case caseexp1
action1
case caseexp2
action2
case caseexp3
action3
% etc: there can be many of these
otherwise
actionn
end
The switch statement begins with the reserved word switch, and ends with reserved word end. switch_expression is compared, in series, to the case expressions (caseexp1, caseexp2, etc.). If the value of the switch_expression matches the caseexp1, for illustration, then action1 is executed and the switch statement ends. If the value matches caseexp3, then the action3 is executed, and in common if the value matches caseexpi, where i can be any of the integer from 1 to n, then actioni is executed. When the value of the switch_expression does not match any of the case expressions, the action is taken after the word or else is executed.