Glossary · CASE

What is CASE statement?

A selection statement that runs one branch depending on an integer or enumerated value. It is what state machines in ST are built from.

It accepts a single label (1:), a list (1, 3, 5:) or a range (10..20:), with an ELSE for everything else, and closes with END_CASE.

It beats a chain of IF/ELSIF for clarity whenever the comparison is always against the same variable, which is exactly the state machine case.

Related terms

State machine
A pattern where the process is in exactly one known state at a time and moves between states on defined conditions.
IF statement
The conditional in ST: IF ... THEN ... ELSIF ... ELSE ... END_IF. The most used statement in the language.

All terms