«IF test-clause

THEN true-clause ELSE false-clause END »

IF … THEN … ELSE … END executes either the true-clausesequence of commands if the test-clauseis true, or the false-clausesequence of commands if the test-clauseis 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 7 THEN 7 ELSE 7 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-clausealgebraic is evaluated.

You can also use the IFTE function with stack syntax. It takes three arguments: a test-resultin level 3, a true-clauseobject in level 2, and a false-clauseobject 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 7 END Structure

The syntax for this structure is « CASE

test-clause1THEN true-clause1END test-clause2THEN truet-clause2END

...

test-clausenTHEN true-clausenEND default-clause (optional)

END »

The CASE … END structure lets you execute a series of test-clausecommands, 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-clausethat’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-clause1is evaluated. If the test is true, true-clause1is executed, and execution skips to END. If test-clause1is false, execution proceeds to test-clause2. 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.

1-14 RPL Programming