Nested switch case

Like nested if, we can use nested switch case in C programming. A switch case statement enclosed inside another switch case statement is called nested switch case.

The syntax of the nested switch cash is as follows:

switch(number) {
   case '1': 
      printf("This 1 is part of outer switch" );
  
      switch(number2) {
         case '1':
            printf("This 1 is part of inner switch" );
            break;
         case '2': /* case code */
      }
   
      break;
   case '2': /* case code */
}
#include
#include 
void main () {
   int m = 50;
   int n = 100; 
   switch(m) {   
      case 50: 
         printf("This is part of outer switch\n", m );      
         switch(n) {
            case 100:
               printf("This is part of inner switch\n", n );
         }
   }
   
   printf("The value of m is : %d\n", m );
   printf("The value of n is : %d\n", n );
 
   getch();
}

Output

This is part of outer switch
This is part of inner switch
Exact value of m is : 50
Exact value of n is : 100