3 - 27 3 - 27
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
3.7.2 Judgment instructions
Use the IF instruction to make a judgment. The IF instruction is entered in the format
shown below.
IF
Condition or
logical expression
THEN
Instruction
executed when the
condition or logical
expression is met
ELSE
Instruction
executed when the
condition or logical
expression is not
met
(1) Specify the condition or logical expression in [Condition or logical expression]
according to the method shown in Section 3.7.1.
(2) Enter the instruction to be executed when [Condition or logical expression] is met
after the THEN instruction. Any instructions can be entered, and it is possible to
use multi-statements ( Section 2.3).
(3) Enter the instruction to be executed when [Condition or logical expression] is not
met after the ELSE instruction. As with (2), any instructions can be entered, and
multi-statements ( Section 2.3) are allowed.
Example
10 FOR I=1 TO 10
20 IF I<=5 THEN PRINT I; "Less than or equal to"
ELSE PRINT I; " G r e a t e r t h a n "
30 NEXT I
40 END
RUN
1 Less than or equal to.
2 Less than or equal to.
5 Less than or equal to.
6 Greater than
10 Greater than
OK
It is not necessary
to split line 20 as
shown here.
You can enter it
in one line.
…
…
…… Executed when I is less than 5
Executed when I is greater tha n
………… ……
REMARK
When the GOTO instruction is placed after the THEN or ELSE instruction, the
GOTO or THEN instruction can be omitted as shown below.
Example
IF A=1 THEN GOTO 100 ELSE GOTO 200
IF A=1 THEN 100 ELSE 200
IF A=1 THEN GOTO 70 ELSE GOTO 10
IF A=1 GOTO 70 ELSE 10
ELSE cannot be omitted.