> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
$schema: https://holocron.so/frontmatter.json
title: Structured Text
description: Structured Text statements, expressions, and control flow supported by the compiler.
icon: lucide:braces
---

Structured Text is **one of the IEC 61131-3 languages** RoboC++ implements for program and action bodies, alongside [Instruction List and SFC](/il-and-sfc) and [native LD and FBD](/native-ld-fbd). PLCopen XML provides another path for graphical LD and FBD.

## Statements

Supported statement forms include:

* Assignment and expression statements
* Function and function block calls (positional and named parameters)
* `IF` / `ELSIF` / `ELSE`
* `CASE` / `OF` / `ELSE`
* `FOR` / `TO` / `BY` / `DO` with `EXIT`
* `WHILE` / `DO` with `EXIT`
* `REPEAT` / `UNTIL`
* `RETURN`

Expression depth and statement nesting are limited by [implementation parameters](/language-support#implementation-limits).

<Aside>
  <Note>
    **`EXIT`** outside `FOR`, `WHILE`, or `REPEAT` bodies is diagnosed during semantic checking.
  </Note>
</Aside>

## Expressions

The supported subset includes:

* Arithmetic, comparison, and logical operators
* `AND` / `OR` / `XOR` / `NOT` on booleans and bit strings with short-circuiting where modeled
* Array indexing and structure field access
* Enum literals and subrange-backed scalars
* `TIME` arithmetic (`+`, `-`) for compatible operands
* Aggregate initializers in supported contexts

Checked integer arithmetic and overflow-safe constant expression checks emit semantic diagnostics when limits are exceeded.

## Functions and EN/ENO

User-defined **`FUNCTION`** POUs parse, check, interpret, and emit to C for basic bodies. Standard functions from the [standard library](/standard-library) are resolved by name.

Functions may use implicit **EN** / **ENO** parameters:

* `EN` gates execution (defaults to enabled when omitted in many calls)
* `ENO` must use output binding (`ENO => Ok`) and expect a `BOOL` target

User-defined **`FUNCTION`** POUs cannot call themselves recursively; call cycles are rejected at check time.

A value-returning **`FUNCTION`** or standard function used as a **standalone statement** (without assignment or output binding) is rejected.

Many standard functions accept **extensible formal inputs** (`IN1`, `IN2`, …) for variadic-style calls such as **`ADD`**, **`MUL`**, **`MIN`**, **`MAX`**, comparisons, and **`CONCAT`**.

## Function blocks

FB instances keep **state across scan cycles**. User-defined FBs use flat state storage in the interpreter and C backend. Standard FBs (`TON`, `CTU`, and others) are documented on the [standard library](/standard-library) page.

**EN/ENO gating** for function-block calls is enforced in interpreter and C output.

## Example

`examples/control_flow.st` exercises `FOR`, `WHILE`, `REPEAT`, `CASE`, and `MAX`:

```bash
cargo run -p rbcpp_cli -- run examples/control_flow.st --cycles 1
```

## Related

* [IL and SFC](/il-and-sfc) for non-ST bodies
* [Execution model](/execution-model) for how bodies run each cycle
* [Examples](/examples) for the full catalog


---

*Powered by [holocron.so](https://holocron.so)*
