100BBasic instructions
7.8 Program control
S7-1200 Programmable controller
212
System Manual, 11/2011, A5E02486680-05
END_CASE
7.8.4
FOR statement
Table 7- 97 Elements of the FOR statement
SCL
Description
FOR "control_variable" := "begin" TO "end"
[BY "increment"] DO
statement;
;
END_FOR;
A FOR statement is used to repeat a sequence of
statements as long as a control variable is within
the specified range of values. The definition of a
loop with FOR includes the specification of an
initial and an end value. Both values must be the
same type as the control variable.
Table 7- 98 Parameters
Parameter
Description
"control_variable"
Required. An integer (Int or DInt) that serves as a loop counter
"begin"
Required. Simple expression that specifies the initial value of the control variables
"end"
Required. Simple expression that determines the final value of the control variables
"increment"
Optional. Amount by which a "control variable" is changed after each loop. The "increment"
has the same data type as "control variable". If the "increment" value is not specified, then
the value of the run tags will be increased by 1 after each loop. You cannot change
"increment" during the execution of the FOR statement.
The FOR statement executes as follows:
●
At the start of the loop, the control variable is set to the initial value (initial assignment)
and each time the loop iterates, it is incremented by the specified increment (positive
increment) or decremented (negative increment) until the final value is reached.
●
Following each run through of the loop, the condition is checked (final value reached) to
establish whether or not it is satisfied. If the condition is satisfied, the sequence of
statements is executed, otherwise the loop and with it the sequence of statements is
skipped.
Rules for formulating FOR statements:
●
The control variable may only be of the data type Int or DInt.
●
You can omit the statement BY [increment]. If no increment is specified, it is automatically
assumed to be +1.
To end the loop regardless of the state of the "condition" expression, use the EXIT statement
(Page 215). The EXIT statement executes the statement immediately following the
END_FOR statement.
Use the CONTINUE statement (Page 214) to skip the subsequent statements of a FOR loop
and to continue the loop with the examination of whether the condition is met for termination.