Operator`s manual

SECTION 3. INSTRUCTION SET BASICS
3-5
If Then/Else comparisons may be nested to form
logical AND or OR branching. Figure 3.8-2
illustrates an AND construction. If conditions A
and B are true, the instructions included between
IF B and the first End Instruction will be
executed. If either of the conditions is false,
execution will jump to the corresponding End
Instruction, skipping the instructions between.
FIGURE 3.8-2. Logical AND Construction
Figure 3.8-3 illustrates the instruction sequence
that will result in subroutine X being executed if
either A or B is true.
IF A (88-92 with command 30)
Call subroutine X (86, command=X)
ELSE (94)
IF B (88-92 with command 30)
Call subroutine X (86, command=X)
END B (95)
END A (95)
FIGURE 3.8-3. Logical OR Construction
A logical OR can also be constructed by setting
a flag if a comparison is true. (The flag is
cleared before making the comparisons.) After
all comparisons have been made, execute the
desired instructions if the flag is set.
The Begin Case Instruction 93 and If Case
Instruction 83 allow a series of tests on the value
in an input location. The case test is started with
Instruction 93 which specifies the location to test.
A series of Instructions 83 are then used to
compare the value in the location with fixed
values. When the value in the input location is
less than the fixed value specified in Instruction
83 the command in that Instruction 83 is
executed; when the next Instruction 83 is
encountered, execution branches to the END
Instruction 95 which closes the case test (see
Instruction 93).
3.8.2 END, INSTRUCTION 95
END, Instruction 95, is required to mark the end
of:
1. A Subroutine (starts with Instruction 87)
2. A Loop (starts with Instruction 85)
3. An IF ... THEN DO sequence (starts with
one of Instructions 89-93 with the THEN DO
command 30).
4. A case statement (starts with Instruction 93)
The IF instructions 89-93 require Instruction 95
only when the THEN DO command 30 is used.
If one of the above instructions is used without
the corresponding END, the 21X will display
error 22 when compiling the program. Error 21
is displayed if END is used without being
preceded by one of these instructions (Section
3.10).
An END instruction is always paired with the
most recent instruction that requires an END and
does not already have one. A way of visualizing
this is to draw lines between each instruction
requiring an END and the END paired with it (as
in Figure 3.8-2). The lines must not cross. To
debug logic or find a missing or extra END error,
list the program and draw the lines.
Subroutines can be called from other
subroutines; they cannot be embedded within
other subroutines. A subroutine must end before
another subroutine begins (Error 20). Any loops
or IF...THEN DO sequences started within a
subroutine must end before the subroutine.
3.8.3 NESTING
A branching or loop instruction which occurs
before a previous branch or loop has been
closed with the END instruction is nested. The
maximum nesting level is 9 deep. Error 30 is
displayed when attempting to compile a program
which is nested too deep.
The Loop Instruction, 87, counts as 1 level.
Instructions 86, 88, 89, 91, and 92 each count as
one level when used with the THEN DO
command 30. Use of Else, Instruction 94, also
counts as one nesting level each time it is used.
For example, the AND construction above is