How to write nested/multi level switch Statement in C programming language?
Switch Statement
On this page
Switch Statement
#include <stdio.h>
int main()
{
int i = 1, j = 3;
// Outer Switch
switch (i) {
// If i == 1
case 1:
// Nested Switch
switch (j) {
// If j == 2
case 2:
printf( "Choice is 2");
break;
// If j == 3
case 3:
printf( "Choice is 3");
break;
}
break;
// If i == 4
case 4:
printf( "Choice is 4");
break;
// If i == 5
case 5:
printf( "Choice is 5");
break;
default:
printf( "Choice is other than 1, 2 3, 4, or 5");
}
return 0;
}
Output
Choice is 3