Nested switch statement in C++ Last Updated : 08 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Switch-case statements: These are a substitute for long if statements that compare a variable to several integral values The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.Switch is a control statement that allows a value to change control of execution. Syntax: switch (n) { case 1: // code to be executed if n = 1; break; case 2: // code to be executed if n = 2; break; default: // code to be executed if // n doesn't match any cases } Nested-Switch Statement: Nested-Switch statements refers to Switch statements inside of another Switch Statements. Syntax: switch(n) { // code to be executed if n = 1; case 1: // Nested switch switch(num) { // code to be executed if num = 10 case 10: statement 1; break; // code to be executed if num = 20 case 20: statement 2; break; // code to be executed if num = 30 case 30: statement 3; break; // code to be executed if n // doesn't match any cases default: } break; // code to be executed if n = 2; case 2: statement 2; break; // code to be executed if n = 3; case 3: statement 3; break; // code to be executed if n doesn't match any cases default: } Example: CPP // Following is a simple program to demonstrate // syntax of Nested Switch Statements. #include <iostream> using namespace std; int main() { int x = 1, y = 2; // Outer Switch switch (x) { // If x == 1 case 1: // Nested Switch switch (y) { // If y == 2 case 2: cout << "Choice is 2"; break; // If y == 3 case 3: cout << "Choice is 3"; break; } break; // If x == 4 case 4: cout << "Choice is 4"; break; // If x == 5 case 5: cout << "Choice is 5"; break; default: cout << "Choice is other than 1, 2 3, 4, or 5"; } return 0; } Output:Choice is 2 Comment More infoAdvertise with us Next Article Nested switch statement in C++ M MinalJain Follow Improve Article Tags : Technical Scripter C++ Programs C++ Computer Science Fundamentals Practice Tags : CPP Similar Reads Switch Statement in C++ In C++, the switch statement is a flow control statement that is used to execute the different blocks of statements based on the value of the given expression. It is an alternative to the long if-else-if ladder which provides an easy way to execute different parts of code based on the value of the e 5 min read C++ Nested if-else Statement Nested if-else statements are those statements in which there is an if statement inside another if else. We use nested if-else statements when we want to implement multilayer conditions (condition inside the condition inside the condition and so on). C++ allows any number of nesting levels.Let's tak 3 min read Interesting facts about switch statement in C Prerequisite - Switch Statement in C Switch is a control statement that allows a value to change control of execution. C // Following is a simple program to demonstrate syntax of switch. #include <stdio.h> int main() { int x = 2; switch (x) { case 1: printf("Choice is 1"); break; cas 3 min read Compound Statements in C++ Compound statements in C++ are blocks used to group multiple statements together into a single unit. These statements are enclosed in curly braces {} and can be used wherever a single statement is expected. The statements put inside curly braces are executed just like a single statement would have b 3 min read C++ if Statement The C++ if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not executed based on a certain condition. Let's take a look at an example:C++#include <iostream> using namespace std; int main() { int 3 min read Like