Switch statement
Switch is a keyword,it is used to create attractive
interaction between the user and application.
break is a statement.It is used to execute the cases
individually.
continue is also a statement. It is used to execute the
the case and continue to another case.
skip is also a statement. It is used to skip the case
to which we mentioned.
jump is also a statement.It is used to jump to the case to
which we mentioned.
Syntax :- {
switch(key)
{
case 0:
statements;
break;
case 1:
statements;
}
}
Example :-
#include<stdio.h>
main()
{
int ch;
clrscr();
printf(" menu\n");
printf("[1]red\n");
printf("[2]blue\n");
printf("[3]green\n");
printf("enter your choice");
scanf(%d",&ch);
switch(ch)
{
case 1:
printf(" your choice is red");
break;
case 2:
printf("your choice is blue");
break;
case 3:
printf("your choice is green");
}
getch();
}
output :-
menu
[1]red
[2]blue
[3]green
enter your choice 1
your choice is red
0 comments:
Post a Comment