CASE instructionΒΆ

With the CASE instructions one can combine several conditioned instructions with the same condition variable in one construct.

Syntax:

CASE <Var1> OF
<Value1>: <Instruction 1>
<Value2>: <Instruction 2>
<Value3, Value4, Value5>: <Instruction 3>
<Value6 .. Value10>: <Instruction 4>

...

<Value n>: <Instruction n>
ELSE <ELSE instruction>
END_CASE;

A CASE instruction is processed according to the following model:

  • If the variable in <Var1> has the value <Value i>, then the instruction <Instruction i> is executed.
  • If <Var 1> has none of the indicated values, then the <ELSE Instruction> is executed.
  • If the same instruction is to be executed for several values of the variables, then one can write these values one after the other separated by commas, and thus condition the common execution.
  • If the same instruction is to be executed for a value range of a variable, one can write the initial value and the end value separated by two dots one after the other. So you can condition the common condition.

Example:

CASE INT1 OF
1, 5: BOOL1 := TRUE;
 BOOL3 := FALSE;
2: BOOL2 := FALSE;
 BOOL3 := TRUE;
10..20: BOOL1 := TRUE;
 BOOL3:= TRUE;
ELSE
 BOOL1 := NOT BOOL1;
 BOOL2 := BOOL1 OR BOOL2;
END_CASE;