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 info M MinalJain Follow Improve Article Tags : C++ Explore C++ BasicsIntroduction to C++3 min readData Types in C++7 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++10 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like