1Ft (If-Then-End Command); Error Traps - HP -28S Manual

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

Advertisement

IF ... THEN ... END
If an ELSE clause isn't required-that is, if the choices are to do
something or do nothing-you can omit ELSE from the program
structure. The following example ensures that the object in level
1
is
greater than the object in level 2 by swapping them if necessary.
IF DUP2 , THEN SWAP END
Note the use of DUP2 to make copies of the objects. The copies are
then consumed by the comparison ,. For another example of IF
THEN ... END, see "SORT (Sort a List)" on page 270.
1FT (If- Then-End Command)
You could write the previous example by using the command 1FT in-
stead of the program structure:
DUP2 ,
«
SWAP» 1FT
The sequence
D U P 2
'leaves a flag on the stack, the program
.,=,:
::;;(.j
A P
:,=,.
goes on the stack, and the command
1FT
takes the flag
and the program as arguments. If the flag is true, 1FT evaluates the
program; if the flag is false, 1FT drops the program. The result is iden-
tical to the program-structure form.
Error Traps
In some cases you can predict that an error might occur during pro-
gram execution. Normally an error cancels program execution; but if
you
trap
the offending command by enclosing it in a special program
structure, the program can continue execution when the error occurs.
Remember the problem with (sin x)/x-it causes an Infinite Result er-
ror when x
=
O. Another method for defining (sin 0)/0
=
1 would
be:
IFERR X SIN X / THEN DROP2 1 END
26: Program Structures
227

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents