6 Programming
6-90
NJ-series CPU Unit Software User’s Manual (W501)
Application:
Use this construct to perform a process depending on evaluation of multiple conditions (condition
expressions).
Description:
If <condition_expression_1> is TRUE, <statement_1> is executed.
If <condition_expression_1> is FALSE and <condition_expression_2> is TRUE, then
<statement_2> is executed.
If <condition_expression_2> is FALSE and <condition_expression_3> is TRUE, then
<statement_3> is executed.
·
·
·
If <condition_expression_n> is TRUE, <statement_n> is executed.
If none of the conditions is TRUE, <statement_m> is executed.
Precautions:
• IF must always be used together with END_IF.
• Write statements that can be TRUE or FALSE for the condition expressions. Example: IF(A>10)
You can also specify BOOL variables (including functions that return a BOOL value) for the condi-
tion expressions instead of an actual expression. In that case, when the variable is TRUE, the
evaluated result is TRUE and when the variable is FALSE, evaluated result is FALSE.
• You can write any of the statements on multiple lines. Separate statements with a semicolon (;).
• You can omit the ELSE statement. If it is omitted, and none of the conditions produces a match,
nothing is done.
Example:
A value of 10 is assigned to variable X when the statement A > 0 is TRUE.
A value of 1 is assigned to variable X when the statement A > 0 is FALSE and statement B = 1 is
TRUE.
A value of 2 is assigned to variable X when the statement A > 0 is FALSE and statement B = 2 is
TRUE.
If none of the conditions is TRUE, a value of 0 is assigned to the variable X.
IF A>0 THEN X:=10;
ELSIF B=1 THEN X:=1;
ELSIF B=2 THEN X:=2;
ELSE X:=0;
END_IF;