IF/SELECT: Difference between revisions

1,103 bytes added ,  4 years ago
No edit summary
 
Line 1:
'''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 primarysimplest conditional instructionsinstruction. WhenThey reached,contain theyan evaluateequation whetherto abe conditionevaluated and an action to be taken if it is true.
 
If the condition is found to be true, it can execute either a [[JMP/LBL|Jump]] or [[CALL|Call]].
[[File:Inst-if orig.gif|thumb|How to add an "IF" instruction. ]]
If it is not true, the instruction will occur as if the line were blank.
 
{| class="wikitable"
!
! colspan="3" |Equation to be Evaluated
! colspan="2" |What happens If Equation is True
|-
! IF
! Variable
Line 28 ⟶ 30:
| LBL[2]
|}
When reached, they evaluate whether the equation is true.
Additionally, when selecting the action field, another condition can be added with the '''AND''' or '''OR''' selection.
 
If the condition is found to be true, it can execute either a [[JMP/LBL|Jump]] or [[CALL|Call]].
[[File:Inst-if orig.gif|thumb|How to add an "IF" instruction. ]]
If it is not true, the instruction will occur as if the line were blank.
 
 
Example: IF R[1] = 1 JMP LBL[2]
 
If this line is reached while R[1] contains 4, nothing will happen. It will skip over the if statement without doing anything.
 
If this line is reached while R[1] contains 1, then "R[1] = 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.
{| class="wikitable"
! IF
Line 51 ⟶ 67:
|JMP
|LBL[2]
|}<br />
 
=== Relational Operators ===
When selecting an IF statement, the first choice to be made is the relational operator within the equation to be evaluated.
Line 112 ⟶ 127:
 
== 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.
{| class="wikitable"
! SELECT
Line 138 ⟶ 153:
|
|=
|14
|Call
|Program3