When writing a program, we need to be able to alter the way that a program is executed depending on the input values or context. Constructs control the flow of our ST routine and allow us to create decision statements, state machines, and loops.
In the following sections, we will explore the various types of constructs available in ST programming.
The IF_THEN construct
We are already familiar with the IF_THEN construct from our simple ST exercise earlier in this chapter. An IF construct will only execute the structured text between IF and END_IF when its expression evaluates as true (1).
IF statements can be nested using the ELSE...IF statement and the ELSE statement can be added to execute when all other statements do not.
In the following example, the IF and ELSE...IF statements are used to check the tank level and pump permissive before starting a pump:
...