Instructions
184Compiler
© 2013 Conrad Electronic
4.2.6.5
if .. else
An if instruction does have the following syntax:
if( Expression ) Instruction1;
else Instruction2;
After the if instruction an Arithmetic Expression will follow in parenthesis. If this Expression is evalu-
ated as unequal 0 then Instruction1 will be executed. By use of the command word else an alternat-
ive Instruction2 can be defined which will be executed when the Expression has been calculated as
0. The addition of an else instruction is optional and is not necessary.
Examples:
if(a==2) b++;
if(x==y) a=a+2;
else a=a-2;
An Instruction Block can be defined instead of a single instruction.
Examples:
if(x<y)
{
c++;
if(c==10) c=0;
}
else d--;
if(x>y)
{
a=b*5;
b--;
}
else
{
a=b*4;
y++;
}
4.2.6.6 switch
If depending on the value of an expression various commands should be executed a switch instruc-
tion is an elegant solution:
switch( Expression )
{
case constant_1:
Instruction_1;
break;