Learn Script ST - aliconnect/aliconnect.sdk GitHub Wiki

Coding ST Structured Text

Program

PROGRAM stexample
  VAR
    x : BOOL;
  END_VAR
  x := TRUE;
  REPEAT
    x := FALSE;
  UNTIL x := FALSE;
  END_REPEAT;
END_PROGRAM;

IF

IF <condition(s)> THEN
 <code>
ELSIF <condition(s)> THEN
 <code>
ELSE
 <code>
END_IF

CASE

Select one of several alternative program sections. ELSE are optional.

CASE <var> OF
 <int>:
 <code>
 <int>:
 <code>
 ELSE
 <code>
END_CASE

FOR

Repeat a sequence of statements as long as a control variable is within the specified range of values

FOR <var> := <int> TO <int> BY <step> DO
 <code>
END_FOR

REPEAT

Repeat a sequence of statements until condition(S) is true. Note minimum one execution.

REPEAT
 <code>
UNTIL <condition(S)>
END_REPEAT

WHILE

Repeat a sequence of statements as long as condition(S) is true.

WHILE <condition(s)> DO
 <code>
END_WHILE

EXIT

Terminates the FOR, WHILE or REPEAT loop in which it resides without regard to any condition

EXIT

RETURN

Terminates Program, Function block call

RETURN
IF condition THEN
    Statement;
    ..
    Statement;
[ ELSEIF condition THEN
    Statement;
    ..
    Statement; ]
[ ELSE
    Statement;
    ..
    Statement; ]
END_IF;

CASE selector OF
label[,label]:
    statement;
label:
    statement;
label:
    statement;
ELSE
    statement;
END_CASE;
⚠️ **GitHub.com Fallback** ⚠️