EasyManua.ls Logo

HP 48GII - Page 41

HP 48GII
653 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
RPL Programming 1-15
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:
! "!452!67!8!9!:;<=!=<>!<=4!1!
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:
! "!#!?!"!?!67!+?98+!:;<=!=<>!<=4!1!1!
The following version uses the IFT command:
! "!452!8!9!"!=<>!1!67:!1!
Example: One Conditional Action. This program multiplies two numbers if both are nonzero.
Program: Comments:
"!
!#!?!@!
Creates local variables x and y containing
the two numbers from the stack.
!"!
!!67!
!!!+?A8+!
!
!!!+@A8+!
!
!!!B=4!
!
!!!:;<=!
!
!!!?!@!.!
!
Starts the test-clause.
Tests one of the numbers and leaves a test
result on the stack. Tests the other
number, leaving another test result on the
stack. Tests whether both tests were true.
Ends the test-clause, starts the true-
clause.
Multiplies the two numbers together only
if AND returns true.
!!!<=4!
!!1!
1!
Ends the true-clause.
The following program accomplishes the same task as the previous program:
! "!#!?!@!"!67!+?!B=4!@+!:;<=!?!@!.!<=4!1!1!
The test-clause 'x AND y' returns “true” if both numbers are nonzero.
The following version uses the IFT command:
! "!#!?!@!"!!+?!B=4!@+!+?.@+67:!1!1!
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.
! "!#!?!"!67!+?C8+!:;<=!?!D6=!?!,!<ED<!3!<=4!1!1!
The following version uses IFTE algebraic syntax:

Table of Contents

Other manuals for HP 48GII

Related product manuals