Nested Switch case in C language by R4R Team

If switch contain another switch inside it then it is said as the Nested switch.

Syntax-
switch(var)
{
case :
switch(var2)
{
}
}


program-

#include< stdio.h>
int main()
{
int a=3;
char b='a';
switch(a)
{
case 1:
printf("case 1 is execute\n");
break;
case 2:
printf("case 2 is execute\n");
break;
case 3:
printf("case 3 is execute\n");
switch(b)
{
case 'a':
printf("Nested Switch");
}
}
}


output-

case 3 is execute
Nested Switch

-In this program, we have a two variable a=1 and b='a'
-we check these value in different cases, then in first switch case 3 is match then it goes inside the other switch.
-In this way we perform a nested switch.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!