To enter CASE END in a program:

1.Press !°%BRCH% !%CASE% to enter CASE … THEN …END…END

2.For each additional testclause, move the cursor af ter a testclause 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 testclause:

« 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:

Comments:

 

 

«

 

→ x y

Creates local variables x and y containing

«

the two numbers from the stack.

 

IF

Starts the testclause.

'x‹0'

Tests one of the numbers and leaves a test

 

result on the stack.

'y‹0'

Tests the other number, leaving another test

 

result on the stack.

AND

Tests whether both tests were true.

THEN

Ends the testclause, starts the trueclause.

x y *

Multiplies the two numbers together only if

 

AND returns true.

END

Ends the trueclause.

»

 

»

 

 

 

The following program accomplishes the same task as the previous program:

«→ x y « IF 'x AND y' THEN x y * END » »

The testclause '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 » »

RPL Programming 115

Page 39
Image 39
HP 48gII Graphing, 50g Graphing manual To enter Case END in a program, Conditional Examples