CASE  OF  ELSE  END_CASE

Statement - Switch to one of various possible statements.

Syntax

CASE <DINT expression> OF
<value> :
    <statements>
<value> , <value> :
    <statements>;
<value> .. <value> :
    <statements>;
ELSE
    <statements>
END_CASE;

Remarks

  • All enumerated values correspond to the evaluation of the DINT expression and are possible cases in the execution of the statements.
  • The statements specified after the ELSE keyword are executed if the expression takes a value which is not enumerated in the switch.
  • For each case, you must specify either:
    • a value.
    • a list of possible values separated by comas (,).
    • a range of values specified by a "min .. max" interval.
  • You must enter space characters before and after the ".." separator.

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* This example check first prime numbers: *)
CASE iNumber OF
0 :
   Alarm := TRUE;
   AlarmText := '0 gives no result';
1 .. 3, 5 :
   bPrime := TRUE;
4, 6 :
   bPrime := FALSE;
ELSE
   Alarm := TRUE;
   AlarmText := 'I don't know after 6 !';
END_CASE;

See Also