If-Then Statement - Siemens SIMATIC S7 System Manual

Hide thumbs Also See for SIMATIC S7:
Table of Contents

Advertisement

100BBasic instructions
7.8 Program control
7.8.2

IF-THEN statement

The IF-THEN statement is a conditional statement that controls program flow by executing a
group of statements, based on the evaluation of a Bool value of a logical expression. You
can also use brackets to nest or structure the execution of multiple IF-THEN statements.
Table 7- 93
Elements of the IF-THEN statement
SCL
IF "condition" THEN
statement_A;
statement_B;
statement_C;
;
[ELSIF "condition-n" THEN
statement_N;
;]
[ELSE
statement_X;
;]
END_IF;
You can include multiple ELSIF statements within one IF-THEN statement.
1
Table 7- 94
Variables for the IF-THEN statement
Variables
"condition"
"statement_A"
"condition-n"
"statement_N"
"statement_X"
An IF statement is executed according to the following rules:
● The first sequence of statements whose logical expression = TRUE is executed. The
● If no Boolean expression = TRUE, the sequence of statements introduced by ELSE is
● Any number of ELSIF statements can exist.
Note
Using one or more ELSIF branches has the advantage that the logical expressions
following a valid expression are no longer evaluated in contrast to a sequence of IF
statements. The runtime of a program can therefore be reduced.
210
Description
If "condition" is TRUE or 1, then execute the following statements until
encountering the END_IF statement.
If "condition" is FALSE or 0, then skip to END_IF statement (unless the
program includes optional ELSIF or ELSE statements).
The optional ELSEIF
evaluated. For example: If "condition" in the IF-THEN statement is FALSE,
then the program evaluates "condition-n". If "condition-n" is TRUE, then
execute "statement_N".
The optional ELSE statement provides statements to be executed when the
"condition" of the IF-THEN statement is FALSE.
The END_IF statement terminates the IF-THEN instruction.
Description
Required. The logical expression is either TRUE (1) or FALSE (0).
Optional. One or more statements to be executed when "condition" is TRUE.
Optional. The logical expression to be evaluated by the optional ELSIF statement.
Optional. One or more statements to be executed when "condition-n" of the ELSIF statement is
TRUE.
Optional. One or more statements to be executed when "condition" of the IF-THEN statement
is FALSE.
remaining sequences of statements are not executed.
executed (or no sequence of statements if the ELSE branch does not exist).
statement provides additional conditions to be
1
System Manual, 11/2011, A5E02486680-05
S7-1200 Programmable controller

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Simatic s7-1200

Table of Contents