# Basic ST Syntax

Source: https://rungs.dev/docs/structured-text/basic-st-syntax

> Statement structure, semicolons, expressions, and basic syntax rules for Structured Text in rungs.dev — the foundation every ST program in the simulator follows.

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 [#basic-structure]

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

```iecst
Variable := Value;
```

Examples:

```iecst
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:

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

## Comments [#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 [#single-line-comments]

Use // for single-line comments:

```iecst

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

### Multi-line Comments [#multi-line-comments]

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

```iecst

/* 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 [#code-examples]

```iecst

// 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.

> **IDEA**
>
> **Practice**
>
> Try it in the [Start/Stop Motor exercise](https://rungs.dev/exercises/start-stop-motor) — latch a motor on with Start and drop it with Stop.