Introduction:
In C++ switch case statement generally evaluates any given expression and based on that value it is supposed to execute certain desired statements that will be associated with them.Switch statements are supposed to be following certain selection control mechanisms; they generally give us the advantage where the value can change the control of execution.They can be considered to be a substitute for long if statements that are generally known to be comparing the variables to several integral values.
They can be considered to be branch statements where they provide us with the functionality of executing various parts of the code which are based on the value of expressions.
An example using the C++ switch case statement :
c++ switch case
Output :-
Enter the serial number of day you want to display: 1 Day – MONDAY
In the above example we can see that the switch case executes the associated statement with the given value of the variable i.e, 1.
The Break Keyword :-
In the language C++ when it reaches the break keyword , it is suppose to break out of that particular switch block. This is supposed to stop the execution of further code and case testing inside the block.
When it is going to encounter the match the final job will be considered to be done and it will break out of that very block.
The Default Keyword:-
This keyword is supposed to run certain default, already specified code if there will be no cases to be run by the switch statements.
Below we can find the example:-
C++ switch case
OUTPUT:-
We are waiting for the weekend