
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) BFlCH IF . Its syntax is:
■s ... IF test-clause THEN true-clause END ... :*■
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) BRCH O IF . Its syntax is:
■ K ... IF test-clause
THEN true-clause ELSE false-clause END’ ... :*■
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
Comentarios a estos manuales