Omron CX-PROGRAMMER V8.1 Operation Manual page 175

Function blocks/ structured text
Table of Contents

Advertisement

Statement Descriptions
IF Statement (Multiple
Conditions)
150
ELSE corresponds to THEN immediately before it, as shown in the above
diagram.
• Multiple statements can be executed within expression_1 and
expression_2. Be sure to use a semicolon (;) delimiter between multiple
statements in an expression.
• The ELSE statement can be omitted. When ELSE is omitted, no opera-
tion is executed if the result of the condition equation is false.
■ Processing Flow Diagram
False
Condition
True
Expression
■ Examples
Example 1: If variable A>0 is true, variable X will be substituted with numerical
value 10. If A>0 is false, variable X will be substituted with numerical value 0.
IF A>0 THEN
X:=10;
ELSE
X:=0;
END_IF;
Example 2: If variable A>0 and variable B>1 are both true, variable X will be
substituted with numerical value 10, and variable Y will be substituted with
numerical value 20. If variable A>0 and variable B>1 are both false, variable X
and variable Y will both be substituted with numerical value 0.
IF A>0 AND B>1 THEN
X:=10; Y:=20;
ELSE
X:=0; Y:=0;
END_IF;
Example 3: If the boolean (BOOL data type) variable A=1(ON), variable X will
be substituted with numerical value 10. If variable A=0(OFF), variable X will
be substituted with numerical value 0.
IF A THEN X:=10;
ELSE X:=0;
END_IF;
■ Summary
This statement is used to execute an expression when a specified condition is
met. If the first condition is not met, but another condition is met, a corre-
sponding expression is executed. If none of the conditions is met, a different
expression is executed.
■ Reserved Words
IF, THEN, ELSIF, (ELSE), END_IF
Section 5-5

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Sysmac ws02-cxpc1-v8Sysmac cx-programmer 8.1

Table of Contents