User`s manual

Dynamic C Users Manual digi.com 43
The switch statement, the most complex branching statement, allows the programmer to phrase a “mul-
tiple choice” branch differently.
First the switch expression is evaluated. It must have an integer value. If one of the const
N
values
matches the switch expression, the sequence of statements identified by the const
N
expression is exe-
cuted. If there is no match, the sequence of statements identified by the default label is executed. (The
default part is optional.) Unless the break keyword is included at the end of the case’s statements, the
program will “fall through” and execute the statements for any number of other cases. The break key-
word causes the program to exit the switch/case statement.
The colons (:) after case and default are required.
switch( expression ){
case const
1
:
statements
1
break;
case const
2
:
statements
2
break;
case const
3
:
statements
3
break;
...
default:
statements
DEFAULT
}