# HP 48gII Advanced User's Reference Manual Page 41

Graphing calculator.

To enter CASE ... END in a program:
1. Press !°%BRCH% !%CASE% to enter CASE ... THEN ...END...END
2. For each additional test-clause, move the cursor after a test-clause END and press @%CASE% to enter THEN
... END.
Conditional Examples
These examples illustrate conditional structures in programs.
Example:
One Conditional Action. The programs below test the value in level 1 — if the value is
positive, it's made negative. The first program uses a command sequence as the test-clause:
« DUP IF 0 > THEN NEG END "
The value on the stack must be duplicated because the > command removes two arguments from the stack (0.
and the copy of the value made by DUP).
The following version uses an algebraic as the test clause:
«  x « x IF 'x>0' THEN NEG END " "
The following version uses the IFT command:
« DUP 0 > « NEG " IFT "
Example:
One Conditional Action. This program multiplies two numbers if both are nonzero.
Program:
«
 x y
«
IF
"
"
The following program accomplishes the same task as the previous program:
«  x y « IF 'x AND y' THEN x y * END " "
The test-clause 'x AND y' returns "true" if both numbers are nonzero.
The following version uses the IFT command:
«  x y « 'x AND y' 'x*y'IFT " "
Example:
Two Conditional Actions. This program takes a value x from the stack and calculates (sin x) /x.
At x= 0 the division would error, so the program returns the limit value 1 in this case.
«  x « IF 'x‹0' THEN x SIN x / ELSE 1 END " "
The following version uses IFTE algebraic syntax:
Creates local variables x and y containing
the two numbers from the stack.
Starts the test-clause.
Tests one of the numbers and leaves a test
'xŠ0'
result on the stack. Tests the other
number, leaving another test result on the
'yŠ0'
stack. Tests whether both tests were true.
Ends the test-clause, starts the true-
AND
clause.
THEN
Multiplies the two numbers together only
if AND returns true.
x y *
END
Ends the true-clause.
RPL Programming 1-15

49g+