150
Statement Descriptions
Section 5-5
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
■
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;
IF Statement (Multiple
Conditions)
■
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
Condition
False
True
Expression
Summary of Contents for SYSMAC CX-Programmer 9
Page 2: ......
Page 4: ...iv ...
Page 6: ...vi ...
Page 8: ......
Page 16: ...xvi ...
Page 20: ...xx ...
Page 26: ...xxvi Application Precautions 4 ...
Page 27: ...Part 1 Function Blocks ...
Page 28: ......
Page 154: ...128 Procedures Section 3 2 ...
Page 155: ...Part 2 Structured Text ST ...
Page 156: ......
Page 160: ...134 CX Programmer Specifications Section 4 2 ...
Page 206: ...180 Procedures Section 6 1 ...
Page 208: ...182 System defined external variables supported in function blocks Appendix A ...
Page 230: ...204 Revision History ...
Page 231: ......