ST Instruction ‘CASE’¶
Use this dialog box for pooling several conditional instructions containing the same condition variable into 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 within the curly brackets {}
is optional.
Processing scheme of a CASE
instruction.
- If the value of the variable
<Var1>
is<value i>
, then the instruction<instruction i>
is executed. - If the variable
<Var1>
has non of the given values, then the<ELSE-instruction>
is executed. - If the same instruction is executed for several values of the variable, then you can write the values in sequence, seperated by commas.
Example
CASE iVar 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;