EasyManuals Logo

Siemens SIMATIC S7-1200 System Manual

Siemens SIMATIC S7-1200
1614 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #320 background imageLoading...
Page #320 background image
Basic instructions
8.8 Program control operations
S7-1200 Programmable controller
320 System Manual, V4.2, 09/2016, A5E02486680-AK
8.8.10.4
FOR statement
Table 8- 157 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.
You can nest FOR loops. The END_FOR state-
ment refers to the last executed FOR instruction.
Table 8- 158 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 "incre-
ment" 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 end condition is not satisfied, the sequence of
statements is executed again, otherwise the loop terminates and execution continues
with the statement immediately following the loop.
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 324). The EXIT statement executes the statement immediately following the
END_FOR statement.
Use the CONTINUE statement (Page 323) 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.

Table of Contents

Other manuals for Siemens SIMATIC S7-1200

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Siemens SIMATIC S7-1200 and is the answer not in the manual?

Siemens SIMATIC S7-1200 Specifications

General IconGeneral
CPU TypeCPU 1211C, CPU 1212C, CPU 1214C, CPU 1215C, CPU 1217C
CommunicationPROFINET
Analog Inputs2
Analog Outputs2
Power Supply24V DC
Expansion ModulesSignal Modules (SM), Communication Modules (CM)
Programming LanguagesLAD, FBD, SCL
Dimensions90 mm x 100 mm x 75 mm
Program Memory50 KB to 150 KB (depending on model)

Related product manuals