100BBasic instructions
7.8 Program control
S7-1200 Programmable controller
210
System Manual, 11/2011, A5E02486680-05
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
Description
IF "condition" THEN
statement_A;
statement_B;
statement_C;
;
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).
[ELSIF "condition-n" THEN
statement_N;
;]
The optional ELSEIF
1
statement provides additional conditions to be
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".
[ELSE
statement_X;
;]
The optional ELSE statement provides statements to be executed when the
"condition" of the IF-THEN statement is FALSE.
END_IF;
The END_IF statement terminates the IF-THEN instruction.
1
You can include multiple ELSIF statements within one IF-THEN statement.
Table 7- 94 Variables for the IF-THEN statement
Variables
Description
"condition"
Required. The logical expression is either TRUE (1) or FALSE (0).
"statement_A"
Optional. One or more statements to be executed when "condition" is TRUE.
"condition-n"
Optional. The logical expression to be evaluated by the optional ELSIF statement.
"statement_N"
Optional. One or more statements to be executed when "condition-n" of the ELSIF statement is
TRUE.
"statement_X"
Optional. One or more statements to be executed when "condition" of the IF-THEN statement
is FALSE.
An IF statement is executed according to the following rules:
●
The first sequence of statements whose logical expression = TRUE is executed. The
remaining sequences of statements are not executed.
●
If no Boolean expression = TRUE, the sequence of statements introduced by ELSE is
executed (or no sequence of statements if the ELSE branch does not exist).
●
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.