Skip to main content

Statement Structure

In Structured Text (ST), each line of logic is written as a statement. Statements define what the PLC should do — such as setting values, evaluating conditions, or calling functions — and must follow a consistent format.

Basic Structure

Each statement ends with a semicolon ( ; ), which acts as a delimiter.

Variable := Value;

Examples:

Motor_On := 1;
Speed := Speed + 5;
Counter := Counter + 1;

Even within control blocks like IF or FOR, every individual statement must end with a semicolon:

IF Temperature > 100 THEN
Fan := 1;
Alarm := 1;
END_IF;

Comments

Comments in ST are used to annotate your code. They are ignored by the PLC but helpful for documenting logic, explaining complex sections, or leaving notes for other programmers.

Single-line Comments

Use // for single-line comments:


// Start the motor if button is pressed
Motor_Start := Start_Button; // Semicolon required

Multi-line Comments

Use /* ... */ for multi-line or block comments:


/* This block handles temperature control.
The fan starts when the temperature exceeds the limit.*/
IF Temp > TempLimit THEN
Fan := 1;
END_IF;

You can also nest comments inside logic when needed, though excessive commenting inside logic blocks can reduce readability.

Code Examples


// This is a single-line comment
Motor_Start := Start_Button; // Semicolon required

/* This is a
multi-line comment explaining
multiple lines of logic */

IF Pressure > 75 THEN
Valve_Open := 0;
END_IF;

Using clear statement formatting and helpful comments improves the readability, maintainability, and collaboration potential of your ST code — especially in large or long-term automation projects.