switch...case
it is used to execute the particular block of the code based on choice.
syntax
switch([choice])
{
case 1://statement1 or block of program;
break;
case 2://statement1 or block of program;
break;
case 3://statement1 or block of program;
break;
}
example,
main()
{
int a;
a=3;
switch(a)
{
case 1:printf("\n one");break;
case 2:printf("\n two");break;
case 3:printf("\n three");break;
case 4:printf("\n four");break;
default:printf("\n values is not equal to 1 to 4 numbers");
}
}
default default is a keyword used to execute the default block pf statements. which means if the switch case the value did not match any cases to execute the default statements. break break is a keyword used to exit control statements statements.
Comments
Post a Comment