Example, If, else, and endif, Using the if and endif commands – Yaskawa LEGEND-MC User Manual
Page 303: Using the else command

293
LEGEND-MC User’s Manual
Example:
Move the A motor to absolute position 1000 counts and back to zero ten times. Wait 100 msec between
moves.
If, Else, and Endif
The LEGEND-MC provides a structured approach to conditional statements using IF, ELSE and ENDIF
commands.
Using the IF and ENDIF Commands
An IF conditional statement is formed by the combination of an IF and ENDIF command. The IF
command has as it's arguments one or more conditional statements. If the conditional statement(s)
evaluates true, the command interpreter will continue executing commands which follow the IF
command. If the conditional statement evaluates false, the controller will ignore commands until the
associated ENDIF command is executed OR an ELSE command occurs in the program (see discussion of
ELSE command below).
NOTE: An ENDIF command must always be executed for every IF command that has been executed. It
is recommended that the user not include jump commands inside IF conditional statements since this
causes re-direction of command execution. In this case, the command interpreter may not execute an
ENDIF command.
NOTE: Do not jump (JP) out of an IF block. If this occurs, the ENDIF instruction will never be
executed.
Using the ELSE Command
The ELSE command is an optional part of an IF conditional statement and allows for the execution of
#BEGIN
Begin Program
COUNT=10
Initialize loop counter
#LOOP
Begin loop
PA 1000
Position absolute 1000
BGA
Begin move
AMA
Wait for motion complete
WT 100
Wait 100 msec
PA 0
Position absolute 0
BGA
Begin move
AMA
Wait for motion complete
WT 100
Wait 100 msec
COUNT=COUNT-1
Decrement loop counter
JP #LOOP,COUNT>0
Test for 10 times thru loop
EN
End Program