CASE Statement

Introduction

The Structured Text CASE statement executes a block of statements based on a selector value. The CASE statement has this syntax:

CASE selector OF
label[,label]:
    statement;
label:
    statement;
label:
    statement;
ELSE
    statement;
END_CASE;

Where:

The ELSE clause is optional.

You can use a range of values for the case labels. For example 0..3: is equivalent to 0,1,2,3:.

Example

(* Translate the pump state into a text string *)
CASE PumpState OF
0:
    StateDescription := "Stopped";
1:
    StateDescription := "Running";
2:
    StateDescription := "Failed";
ELSE
    StateDescription := L"Invalid";
END_CASE;

Further Information

Structured Text

For other Structured Text (ST) statement types.

Expressions

To learn about expressions that can be used as selector and label values.

Glossary

For the meaning of terms used in Fernhill SCADA.