CASE statement in ST

Syntax
CASE ... OF
...
ELSE ...
END_CASE

Meaning

Use the CASE statement to specify that a group of statements is to be executed, if the evaluated value of the selector (entered after CASE) corresponds to a label which is entered for this group of statements. If the value of the selector does not correspond to any of the labels, then either no statement is to be executed, or the statement group following the ELSE keyword is to be executed,

Restriction

You are only allowed to enter such →expressions for the selector that can be evaluated to be of the →generic data type ANY_INT.

A label may be one or more integer →literals/→variables, enumerated values or subranges and must be evaluated as →constant value during the runtime. The data type of the labels must be implicitly convertible into the data type of the selector.

Example
FUNCTION_BLOCK ExampleIfAndCaseDocumentation
VAR
up : BOOL;
count : INT;
notify : STRING[1000];
END_VAR
VAR CONSTANT
neg100 : int := -100;
neg1 : int := -1;
END_VAR
IF up THEN /* If 'up' = 'TRUE', counter counts up. */
count := count + 1;
ELSE
count := count - 1;
END_IF;
CASE count OF /* If 'count' is in the respective range of values, 'notify' displays the appropriate text. */
0 : notify := 'Counter is 0.';
1..100 : notify := 'Counter is in the range between 1 and 100.'; /* This label defines a subrange with integer values. */
neg100..neg1 : notify := 'Counter is in the range between -100 and -1.'; /* This label defines a subrange with constant variables. */
ELSE
notify := 'Counter is more than 100 or less than -100.';
END_CASE;
END_FUNCTION_BLOCK