ELSE statements
Oftentimes, we’ll need a default block of code to run if the IF statement does not evaluate to TRUE. To accomplish this, the ELSE statement is employed. The ELSE statement is like a catcher in a baseball game. If the batter misses the ball, it’s the catcher’s job to catch the ball and throw it back to the pitcher. Consider the following example:
If motor1 = selected then turn on motor1 turn off motor2 Else turn on motor2 turn off motor1
For this example, if motor1 is selected, that motor will turn on. If motor1 is not selected, then motor2 will turn on. Again, the ELSE block is like the catcher; if motor1 is not selected, it will catch that and turn on motor2. To see this in action, implement the following variables:
PROGRAM PLC_PRG VAR selectMotor1 ...