EasyManuals Logo

HP HP-28S User Manual

HP HP-28S
341 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #228 background imageLoading...
Page #228 background image
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

Table of Contents

Other manuals for HP HP-28S

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the HP HP-28S and is the answer not in the manual?

HP HP-28S Specifications

General IconGeneral
BrandHP
ModelHP-28S
CategoryCalculator
LanguageEnglish

Related product manuals