|
Section 11: Branching and Looping163
|
|
|
|
The modification creates an infinite loop in the program; it now
computes an infinite series of numbers that approaches the value
of pi. Run the program and watch the values as they approach π.
Set the calculator to FIX 9 so you can see
the complete display.
|
|
|
|
|
Controlled Looping
|
|
The HP-41C has two powerful functions that make looping in your
programs very easy. These functions are
ISG (increment and skip if greater)
and DSE
(decrement and skip if equal). Both functions contain internal
counters that allow you to control the execution of the loop.
|
|
These two functions use a number that is interpreted in a special way
to control program loops. The number is stored into any storage register
(even the stack). The format of the number is:
|
|
|
|
where:
|
|
|
iiiii
is the current counter value,
|
|
|
fff
is the counter test value, and
|
|
|
cc
is the increment value.
|
|
|
The iiiii portion of the number
tells the HP-41C that you wish to count the number of passes through
the loop beginning with that number. If you do not specify an
iiiii value, the HP-41C assumes
you wish to begin counting at zero. An
iiiii value can be specified as
one to five digits.
|
|
The fff portion of the number
tells the HP-41C that you wish to stop the counting at that number.
The fff value must always be
specified as a three-digit number (e.g., an
fff value of 10 would be specified
as 010). If you do not specify an
fff value, the HP-41C assumes you
wish to stop counting at zero.
|