1-14 RPL Programming
The IF … THEN … ELSE … END Structure
The syntax for this structure is
! «!…!IF!test-clause
!! THEN!true-clause!ELSE!false-clause!END!…!»
IF … THEN … ELSE … END executes either the true-clause sequence of commands if the true-clause is true,
or the false-clause sequence of commands if the true-clause is false. 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, the false-clause is executed. After the appropriate
clause is executed, execution resumes following END. See "Conditional Examples" on page 1-15.
To enter IF … THEN … ELSE … END in a program:
! Press !°%BRCH% @%#IF#% .
The IFTE Function
The algebraic syntax for this function is 'IFTE( test, true-clause, false-clause)'
If test evaluates true, the true-clause algebraic is evaluated — otherwise, the false-clause algebraic is evaluated.
You can also use the IFTE function with stack syntax. It takes three arguments: a test-result in level 3, a true-
clause object in level 2, and a false-clause object in level 1. See "Conditional Examples" on page 1-15.
To enter IFTE in a program or in an algebraic:
! Press !°%BRCH% L!%IFTE% .
The CASE … END Structure
The syntax for this structure is
! « … CASE
test-clause
1
THEN true-clause
1
END
test-clause
2
THEN truet-clause
2
END
...
test-clause
n
THEN true-clause
n
END
default-clause (optional)
!! END!…!»
The CASE … END structure lets you execute a series of test-clause commands, then execute the appropriate
true-clause sequence of commands. The first test that returns a true result causes execution of the corresponding
true-clause, ending the CASE … END structure. Optionally, you can include after the last test a default-clause
that's executed if all the tests evaluate to false. If a test-clause is an algebraic, it's automatically evaluated to a
number — you don't need "NUM or EVAL.
When CASE is executed, test-clause
1
is evaluated. If the test is true, true-clause
1
is executed, and execution
skips to END. If test-clause
1
is false, execution proceeds to test-clause
2
. Execution within the CASE structure
continues until a true-clause is executed, or until all the test-clauses evaluate to false. If a default clause is
included, it's executed if all the test-clauses evaluate to false. See "Conditional Examples" below.