ST instruction CASE
The CASE instruction is used to group multiple conditional instructions with the same conditional variable in a construct.
Syntax:
CASE <Var1> OF
<value1>:<instruction1>
<value2>:<instruction2>
<value3, value4, value5>:<instruction3>
<value6 ... value10>:<instruction4>
...
<value n>:<instruction n>
{ELSE <ELSE-instruction>}
END_CASE;
The section inside the curly braces {} is optional.
Processing scheme of a CASE instruction:
- If the variable <Var1> has the value <value i>, <instruction i> is executed.
- If the variable <Var1> has none of the specified values, the <ELSE instruction> is executed.
- If you want to execute the same instruction for multiple values of the variable, you can write these values separated by commas.
Example:
CASE nVar OF
1,5 : bVar1 := TRUE;
bVar3 := FALSE;
2 : bVar2 := FALSE;
bVar3 := TRUE;
10..20 : bVar1 := TRUE;
bVar3 := TRUE;
ELSE
bVar1 := NOT bVar1;
bVar2 := bVar1 OR bVar2;
END_CASE;