TIA Portal · Deep dive D1 · expands Track 03

SCL, step by step

Structured Control Language is TIA's text language for writing PLC logic. It is useful for calculations, loops and array operations because you can read the sequence of operations directly. To follow that sequence, step through this example with the current line and variable values visible together. Watch when each value changes before running the whole block.

FOR / WHILEIF / CASE#temp vars
01 · Run it line by line

A loop that finds the peak & average

This block reads six values from an array, keeps the highest reading and calculates their average. Press ⏭ Step to execute the next line and inspect the resulting variable values. The yellow line marker shows what will run next. ▶ Run continues through the sequence automatically so you can compare the full execution with the individual steps.

Live variables

press Step to begin…
line pending / total pending

The FOR i := 1 TO 6 loop executes its body six times. After each pass, execution returns to the loop test until the iterations are complete. An explicit loop makes this repeated calculation easy to follow in SCL. The # prefix identifies a block-local variable, including temporary and static variables; "Data" uses a quoted DB name to access its data.

02 · SCL constructs

Loops, decisions and data access

🔁 FOR / WHILE / REPEAT repeat a sequence of statements. Use them to visit array elements, accumulate a sum or search for a value while keeping the loop condition visible.

🔀 IF / ELSIF / CASE select which statements run. A CASE on a step number can express the transitions of a state machine without repeating the same comparison for each branch.

🧮 Operators & functions include + - * / MOD, SQRT(), ABS() and comparisons. These expressions let you write the calculation directly and inspect its intermediate values as the block executes.

📦 #temp vs static vs "DB" refer to different kinds of storage: #x is local, a VAR in an FB persists, "Recipe".x refers to data in a DB. The storage and lifetime rules are the same ones introduced in Blocks & Reuse; choosing SCL does not change them.

03 · Check yourself

Spot the SCL job

Which task would benefit most from an SCL loop or expression?