Using programming structures, Using programming structures -10, Conditional structures – HP 48g Graphing Calculator User Manual
Page 416
Attention! The text in this document has been recognized automatically. To view the original document, you can use the "Original mode".

Using Programming Structures
A programming structure allows a program to make a decision about
how it should execute depending on given conditions or the values of
particular arguments. Careful use of these structures make it possible
to create programs of extraordinary flexibility.
29
Conditional Structures
Conditional structures let a program make a decision based on the
result of one or more tests.
Here is a summary of the conditional structures available on the
HP 48:
IF...THEN...END
Enter this structure into a program by pressing
fPRG)
B F lC H
IF
. Its syntax is:
■ s ... IF
test-clause
T H E N
true-clause
E N D ... :* ■
IF...THEN...END executes the sequence of commands in the
true-clause only if the test-clause evaluates to true. The test-clause
can be a command sequence (for example, fl B fi) or an algebraic (for
example, '
flilB
‘), If the test-clause is an algebraic, it’s automatically
evaluated to a number—you don’t need ^NUM or EVAL.
IF begins the test-clause, which leaves a test result on the stack.
THEN removes the test result from the stack. If the value is nonzero,
the true-clause is executed—otherwise, program execution resumes
following END.
IF...THEN...ELSE...END
Enter this structure into a program by pressing
(PRG)
B R C H
O
IF
. Its syntax is:
■ K
... IF
test-clause
T H E N
true-clause
E L S E
false-clause
E N D ’ ... :* ■
IF...THEN...ELSE...END executes either the true-clause sequence of
commands if the test-clause is true, or the false-clause sequence of
commands if the test-clause is false. If the test-clause is an algebraic.
29-10 Programming the HP 48