❖ C++ switch Statement :-
Consider a situation in which, only one block of code needs to be executed among many blocks. This type of situation can be handled using nested if...else statement but, the better way of handling this type of problem is using switch...case statement.
Syntax of switch:-
Switch(expression)
{
Case value1 : statement1;
Break;
Case value2 : statement2;
Break;
Default : default statements;
}
The expression is either an integer or a character in above syntax. If the expression matches constant in case, the relevant codes are executed and control moves out of the switch statement. If the expression doesn't matches any of the constant in case, then the default statement is executed and control moves out of switch statement.
Flowchart of switch Statement:-
Output:-
Enter the no
2
two
Comments
Post a Comment