CASE Statement

Help Contents

Introduction

The IEC 61131-3 ST 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:.

Examples

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

Standards Compliance

IEC 61131-3 Second Edition: Table 56.5.

IEC 61131-3 Third Edition: Table 72.5.

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.