Program Control; Goto; Branching And Looping - HP -11C Owner's Handbook Manual

Hide thumbs Also See for HP-11C:
Table of Contents

Advertisement

112
Section 7: Program Decisions and Control
Program Control
GoTo
The [GTO]instruction you have used earlier to position the calcula-
tor to a specific program line for viewing or editing is also used to
transfer execution to a label elsewhere in program memory. When
used as an instruction in a program [GTO]is followed by an alpha or
numeric label address,
i
|
I
Instruction
|
|
=
Instruction
|=
=
7
¥
When a running program encounters
a
(GTO}
/abel instruction,
execution is suspended while the calculator searches downward in
memory for the specified label. Program execution resumes at the
first line found to contain the label.
Branching and Looping
Unconditional Branching. An unconditional branch is simply
instruction that is always executed in a running program to
transfer program execution elsewhere in the program, regardless of
data status, The preceding illustration of [GTO] operation is an
unconditional branch.
Conditional Branching. When
[GTO] /abel is used in conjunction
with a conditional test, as in the following illustration, the [GTO]
label instruction becomes a conditional branch. That is, the result
of the conditional test preceding the [GTO] determines whether or
not the [GTO]instruction will be executed.
en
ee
~~
we
wr
wv
ww
i a a
a Oe
Oe
we Y
Section 7: Program Decisions and Control
113
Conditional Branch
(x <y) = False
(x <y) =True
(Hite
[instruction |
When the calculator is in Run mode, pressing [GTO}/abel causes the
calculator to go to the specified label and halt. This feature is
convenient when you want to review or edit lines of memory
following a certain label instead of executing them as part of a
program.
Looping. Looping is a special case of branching in which a (GTO)
instruction is used to repeat the execution of a series of instructions
'one or more times. Loops are frequently used for counters and for sequen-
tially calculating a series of results using the same set of program
instructions. The continuation of a loop for a new iteration or the
transfer of execution out of a loop is controlled by a conditional
branch.
In the following illustration, as long as the result of the conditional
test preceding the [GTO]is true the calculator continues successive
iterations of the loop. When the result of the loop conditional test
becomes false, execution skips the (GTO) instruction and continues
with the rest of the program. Use of an unconditional branch to
control a loop results in an infinite loop, that is, a loop that is
reexecuted indefinitely.

Advertisement

Table of Contents
loading

Table of Contents