# IF/SELECT

IF statements are the primary conditional instructions. Conditional instructions allow programs to change based on the status of variables within the system. Unconditional instructions such as register instructions, I/O instructions, or simple Motion Instructions will always do exactly what they are written to do when the line is reached in the program. Conditional instructions will only perform their associated action in the event the equation they contain is found to be true.

## IF Statements

IF statements are the simplest conditional instruction. They contain an equation to be evaluated and an action to be taken if it is true.

Equation to be Evaluated What happens If Equation is True
IF Variable Relational Operator Variable Action Destination
IF R = 1 Call Program1
IF DI = ON JMP LBL

When reached, they evaluate whether the equation is true.

If the condition is found to be true, it can execute either a Jump or Call.

If it is not true, the instruction will occur as if the line were blank.

Example: IF R = 1 JMP LBL

If this line is reached while R contains 4, nothing will happen. It will skip over the if statement without doing anything.

If this line is reached while R contains 1, then "R = 1" is true. This means it will perform the action it is given, which was jump to label 2.

Additionally, when selecting the action field by cursoring to it or touching it on the touchscreen, another condition can be added with the AND or OR selection.

IF Variable Relational Operator Variable Modifier Variable Math Variable Action Destination
IF R = 1 AND R > AI JMP LBL

### Relational Operators

When selecting an IF statement, the first choice to be made is the relational operator within the equation to be evaluated.

Relational Operator Types
Symbol Name Evalues To "True" When
= Equal To The left variable is equal to the right variable.
<> Not Equals The left variable is not equal to the right variable.
< Less Than The left variable is less than the right variable.
<= Less Than or Equal To The left variable is less than or equal to the right variable.
> Greater Than The left variable is greater than the right variable.
>= Greater Than or Equal To The left variable is greater than or equal to the right variable.
(...) Mixed Logic

### Actions

In the event the equation evaluates as true, an action will occur. The following table lists the possible actions an IF statement can take.

Action Types
Action Destination Description
JMP LBL[#] The program will jump to the labeled line and continue from there.
CALL Program A program is CALLED. When the called program reaches the [END] instruction, it will return to the next line after the IF statement.
Call Program()

## SELECT Statements

When wanting to make a large list of possible conditions for a single variable, you'll likely want to use the SELECT option. SELECT is outside the scope of the MH-142 course but is useful none the less.

SELECT Variable Math Variable Action Destination
SELECT R = 1 Call Program1
= 2 Call Program2
= 4 Call Program3
Else JMP LBL2