Testing Object Types

The TYPE command (!°%TEST% L %TYPE%) takes any object as its argument and returns the number that identifies that object type. For example, "HELLO" TYPE returns 2, the value for a string object. See the table of object types in chapter 3, in the TYPE command, to find calculator objects and their corresponding type numbers.

Testing Linear Structure

The LININ command (!°%TEST% !«%LININ%) takes an algebraic equation on level 2 and a variable on level 1 as arguments and returns 1. if the equation is linear for that variable, or 0. if it is not. For example, 'H+Y^2' 'H' LININ returns 1. because the equation is structurally linear for H. See the LININ command in chapter 3 for more information.

Using Conditional Structures and Commands

Conditional structures let a program make a decision based on the results of tests.

Conditional commands let you execute a trueclause or a falseclause (e ach of which are a single command or object). These conditional structures and commands are contained in the PRG BRCH menu (!°%BRCH%):

IF … THEN … END structure.

IF … THEN … ELSE … END structure. CASE … END structure.

IFT (ifthen) command. IFTE (ifthenelse) function.

The IF THEN END Structure

The syntax for this structure is

« IF testclause THEN trueclause END »

IF … THEN … END executes the sequence of commands in the trueclause only if the testclause evaluates to true. The testclause can be a command sequence (for example, A B ‰) or an algebraic (for example, 'A‰B'). 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, program execution resumes following END. See “Conditional Examples” on page 115.

To enter IF THEN END in a program:

Press !°%BRCH% !%IF% .

The IFT Command

The IFT command takes two arguments: a testresult in level 2 and a trueclause object in level 1. If the testresult is true, the trueclause object is executed — otherwis e, the two arguments are removed from the stack. See “Conditional Examples” on page 115.

To enter IFT in a program:

Press !°%BRCH% L!%IFT% .

The IF THEN ELSE END Structure

The syntax for this structure is

RPL Programming 113

Page 37
Image 37
HP 48gII Graphing manual Using Conditional Structures and Commands, To enter if then END in a program, Press !%BRCH% !%IF%