CASE Statement

CASE values must be integer constant expressions. Several values, separated by commas, can lead to the same list of statements. The ELSE statement is optional.
CASE Statement
Name
CASE ... OF ... ELSE ... END_CASE
Meaning
executes one of several lists of ST statements
Syntax
CASE <integer_expression> OF <value> : <statements> ; <value> , <value> : <statements> ; ... ELSE <statements> ; END_CASE;
Example
(* ST program using CASE statement *) CASE error_code OF 255: err_msg := 'Division by zero'; fatal_error := TRUE; 1: err_msg := 'Overflow'; 2, 3: err_msg := 'Bad sign'; ELSE err_msg := 'Unknown error'; END_CASE;
To insert a CASE
  • From the
    Toolbox
    , drag the
    CASE
    element into the language container.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal