«IF testclause

THEN trueclause ELSE falseclause END »

IF … THEN … ELSE … END executes either the trueclause sequence of commands if the testclause is true, or the falseclause sequence of commands if the testclause is false. If the testclause is an algebraic, it’s automatically evaluated to a number — you don’t need →NUM or EVAL.

IF begins the testclause, which leaves a test resu lt on the stack. THEN removes the test result from the stack. If the value is nonzero, the trueclause is executed — oth erwise, the falseclause is executed. After the app ropriate clause is executed, execution resumes following END. See “Conditional Examples” on page 115.

To enter IF THEN ELSE END in a program:

Press !°%BRCH% @%#IF#% .

The IFTE Function

The algebraic syntax for this function is 'IFTE( test, trueclause , falseclause )'

If test evaluates true, the trueclause algebraic i s evaluated — otherwise, the falseclause algebraic is evaluated.

You can also use the IFTE function with stack syntax. It takes three arguments: a testresult in level 3, a trueclause object in level 2, and a falseclause object in level 1. See “Conditional Examples” on page 115.

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

testclause 1 THEN trueclause 1 END testclause 2 THEN truetclause 2 END

...

testclause n THEN trueclause n END defaultclause (optional)

END »

The CASE … END structure lets you execute a series of testclause 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 defaultclause that’s executed if all the tests evaluate to false. If a testclause is an algebraic, it’s automatically eval uated to a number — you don’t need →NUM or EVAL.

When CASE is executed, testclause 1 is evaluated. If the test is true, trueclause 1 is executed, and execution skips to END. If testclause 1 is false, execution proceeds to testclause 2. Execution within the CASE structure continues until a trueclause is executed, or until all the t estclauses evaluate to false. If a default clause is included, it’s executed if all the testclauses evaluate to false. See “Conditional Examples” below.

114 RPL Programming

Page 38
Image 38
HP 50g Graphing, 48gII Graphing manual To enter if then Else END in a program, Press !%BRCH% @%#IF#%, Press !%BRCH% L!%IFTE%