If a program begins with a local variable structure and has a program as the defining procedure, the complete program acts like a userdefined function in two wa ys: it takes numeric or symbolic arguments, and takes those arguments either from the stack or in algebraic syntax. However, it does not have a derivative. (The defining program must, like algebraic defining procedures, return only one result to the stack.)

There’s an advantage to using a program as the defining procedure for a local variable structure: The program can contain commands not allowed in algebraic expressions. For example, loop structures are not allowed in algebraic expressions.

Using Tests and Conditional Structures

You can use commands and branching structures that let programs ask questions and make decisions. Comparison functions and logical functions test whether or not specified conditions exist. Conditional structures and conditional commands use test results to make decisions.

Testing Conditions

A test is an algebraic or a command sequence that returns a test result to the stack. A test result is either true — indicated by a value of 1. — or it is false — indicated by a value of 0..

To include a test in a program:

To use stack syntax, enter the two arguments, then enter the test command. To use algebraic syntax, enter the test expression (with ‘ delimiters).

You often use test results in conditional structures to determine which clause of the structure to execute. Conditional structures are described under Using Conditional Structures and Commands, page 113.

Example: Test whether or not X is less than Y. To use stack syntax, enter X Y <. To use algebraic syntax, enter 'X<Y'. (For both cases, if X contains 5 and Y contains 10, then the test is true and 1. is returned to the stack.)

Using Comparison Functions

Comparison functions compare two objects, using either stack syntax or algebraic syntax.

Comparison Functions

Key

Programmable

Description

 

Command

 

 

 

 

„°%TEST% (pages 1 and 2):

 

 

 

%$==$%

= =

Tests equality of two objects.

%%´%%

Not equal.

%#%<%%

<

Less than.

%#%>%%

>

Greater than.

%#%»%%

Less than or equal to.

Greater than or equal to.

#%%¼%%

SAME

Identical. Like = =, but doesn’t allow a

##SAME##

 

comparison between the numerical value of

 

 

 

 

an algebraic (or name) and a number. Also

 

 

considers the wordsize of a binary integer.

 

 

 

The comparison commands return 1. (true) or 0. (false) based on the comparison — or an expression that can evaluate to 1. or 0.. The order of the comparison is “level 2 test level 1,” where test is the comparison function.

All comparison commands except SAME return the following:

RPL Programming 111

Page 35
Image 35
HP 48gII Graphing, 50g Graphing Using Tests and Conditional Structures, Testing Conditions, To include a test in a program