Conditional Structures - HP -28S Manual

Advanced scientific calculator
Hide thumbs Also See for HP-28S:
Table of Contents

Advertisement

For example, the user function COT (from chapter 5) was written:
Here the local-variable structure stores one argument in a local vari-
able }:: (satisfying the first requirement) and evaluates the expression
, I
t,fI..!
0::
TAt·l
0::
::<::0 : : 0 '
(satisfying the second requirement). The user func-
tion O-C (from chapter 14) included a program rather than an
expression but, since the program returned exactly one result, O-C
also satisfied the second requirement.
These requirements apply only to user functions. More generally, local
variables are used as a substitute for stack manipulations. The follow-
ing example returns the sum and difference of two numbers. Since it
returns two results, it can't be a user function.
«
~
x
y
«
x y
+ x y -
» »
For more examples, see the programs in chapter 28. They use local-
variable structures more often to avoid stack manipulations than to
create user functions.
Conditional Structures
Conditional structures enable a program to test a specified condition
and make a decision based on the result of the test. This section first
gives an example of a conditional structure.
It
uses that example to
discuss program structures in general, and then it describes other
types of conditional structures.
Suppose you're writing a program that uses the variable x, and you
want to calculate (sin
x)jx.
A problem arises because the quotient is
undefined when
x
=
O. The following example returns (sin
x)jx
if
x
=1=
0, or returns 1 if
x
=
O.
IF X 0
~
THEN X SIN X / ELSE 1 END
26: Program Structures
223

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents