Instructions

185 C-Control Pro IDE
© 2013 Conrad Electronic
case constant_2:
Instruction_2;
break;
.
.
case constant_n:
Instruction_n;
break;
default: // default is optional
Instruction_0;
};
The value of the Expression is calculated. Then the program execution will jump to the constant cor-
responding to the value of the Expression and will continue the program from there. If no constant
corresponds to the value of the expression the switch construct will be left.
If a default is defined within a switch instruction then the instructions after default will be executed
if no constant corresponding to the value of the instruction has been found.
Example:
switch(a+2)
{
case 1:
b=b*2;
break;
case 5*5:
b=b+2;
break;
case 100&0xf:
b=b/c;
break;
default:
b=b+2;
}
The execution of a switch statement is highly optimized. All values are stored inside a
jumptable. Therefore exists a constraint that the calculated Expression is of type signed 16 Bit In-
teger (-32768 .. 32767). For this reason a e.g. "case > 32767" is rather senseless.
break Instruction
A break will leave the switch instruction. If break is left out ahead of case then the instruction will
be executed even when a jump to the preceeding case does take place:
switch(a)
{
case 1:
a++;