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 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|
When reached, they evaluate whether the equation is true.
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.
When selecting an IF statement, the first choice to be made is the relational operator within the equation to be evaluated.
|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.|
In the event the equation evaluates as true, an action will occur. The following table lists the possible actions an IF statement can take.
|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.|
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.