Instead of writing many if..else if statements, you can use the switch statement to execute one of many code blocks.
The switch expression is evaluated once. The value of the expression is compared with the values of each case. If there is a match, the associated block of code is executed.
int day = 4;
switch (day) {
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
case 3:
cout << "Wednesday";
break;
case 4:
cout << "Thursday";
break;
default:
cout << "Weekend!";
}
// Outputs: Thursday
break and default Keywordsbreak: Stops the execution of more cases inside the switch. Without it, the code will continue to execute the next cases even if they don't match!default: Optional. Specifies some code to run if there is no case match.Which keyword is used to stop the execution of more cases inside a switch statement?