Control Flow
How the ST body makes decisions and repeats work — comparisons, logical operators, IF and FOR — each with a small, complete example. (For writing values see Assignment; for maths see Arithmetic.)
Comparison & logical operators
These build the conditions that IF and loops test:
| Group | Operators |
|---|---|
| Comparison | = <> < <= > >= |
| Logical | AND OR NOT |
Aliases: comparison accepts ==/!= for =/<>, and &&/||/! for AND/OR/NOT. Remember: a single = is a comparison; to write a value use :=.
Conditional: IF / ELSIF / ELSE
(* Two-sided temperature guard *) IF Global.Temp >= Param.TripLimit THEN Global.Cooling := TRUE; Global.Heating := FALSE; ELSIF Global.Temp <= Param.LowLimit THEN Global.Cooling := FALSE; Global.Heating := TRUE; ELSE Global.Cooling := FALSE; Global.Heating := FALSE; END_IF;
Loop: FOR ... DO ... END_FOR
(* Clear the first N slots of an array *) FOR i := 0 TO Param.Count - 1 DO Global.Buffer[i] := 0; END_FOR; (* BY sets the step *) FOR i := 0 TO 10 BY 2 DO Global.Evens[i] := i; END_FOR;
Use EXIT; to break out of a loop early and CONTINUE; to skip to the next iteration. Loops are capped at 10,000 iterations per scan.
Comments
Two styles: // line comment and (* block comment *).
Not supported: CASE, WHILE and REPEAT are not part of the block language — express those with IF and FOR. There are also no maths helpers like ABS/MIN/MAX/SQRT, and the aggregate/state functions ALL, ANY, NONE, IN_STATE, QUEUE_* belong to the Conditions language, not to ST block bodies.