C Language Notes_5
C Language Notes_5
Syntax:
SWITCH
It is a selection statement.
It is used to execute one case of statements from no
of cases according to the switch expression value
matched with case expression value. In switch the
program is jumped to matching case like the go to
label.
It is similar to ladder if in working style.
Switch performance is high when compared with
ladder if because of it jumps to matching case.
11
Syntax:
switch(expression)
{
case constexp1:
statements;
break;
case constexp2:
statements;
break;
case constexpN:
statements;
break;
[ default: statements; ]
}
Here switch, case, break, default are the keywords.
In between case and case expression / value at least
one space should be provided. Otherwise it will
become a label.
12