11 - 84 11 - 84
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
IF GOTO ELSE
Instruction
IF to GOTO to ELSE
• Selects a branch destination according to the result of an expression.
IF <conditional expression> GOTO <line number> [ ELSE <instruction> / <line
number> ]
conditional expression
• • • •
Specify with a relational operation expression (<, >,
=).
line number
• • • •
Specify a line number of execution destination that is
executed when the conditional expression is true.
Syntax
instruction/line number
• • • •
Specify the instruction that is executed when the
conditional expression is false, or a line number of
execution destination.
IF X> Y GOTO 100 ELSE
END
• • • •
Branches to line 100 when X is greater than Y.
Otherwise, terminates the program execution.
Examples
IF X=0 GOTO 100 ELSE
200
• • • •
Branches to line 100 if X is 0. If X is not 0, branches
to line 200.
Description
• The IF to GOTO to ELSE instruction selects the execution according to the result of the
expression.
• If the condition of <conditional expression> is true, the instruction after GOTO is executed
and the instruction after ELSE is ignored.
• If the condition of <conditional expression> is false, the instruction after GOTO is ignored
and the instruction after ELSE is executed.
The execution moves to the instruction of the next line if ELSE is not specified.
• <line number> can also be specified by a label.
• The IF instruction can be nested by writing a separate IF instruction after ELSE.
Example IF <conditional expression 1)> GOTO 100 100 ELSE IF <conditional
expression 2)> GOTO 200 ELSE 300
Line 100
Conditional
expression
1)
Conditional
expression
2)
YES
YES
Line 200
Line 300
NO
NO