Example: Multiple Conditional Actions. The following program stores the level 1 argument in a variable if the argument is a string, list, or program.

Program:

Comments:

 

 

«

 

→ y

Defines local variable y.

«

Starts the defining procedure.

CASE

Starts the case structure.

y TYPE 2 SAME

Case 1: If the argument is a string, stores

THEN y 'STR' STO END

it in STR.

y TYPE 5 SAME

Case 2: If the argument is a list, stores it

THEN y 'LIST' STO END

in LIST.

y TYPE 8 SAME

Case 3: If the argument is a program,

THEN y 'PROG' STO END

stores it in PROG.

END

Ends the case structure.

»

Ends the defining procedure.

»

 

 

 

Using Loop Structures

You can use loop structures to execute a part of a program repeatedly. To specify in advance how many times to repeat the loop, use a definite loop. To use a test to determine whether or not to repeat the loop, use an indefinite loop.

Loop structures let a program execute a sequence of commands several times. Loop structures are built with commands — called structure words — that work only when used in proper combination with each other. These

loop structure commands are contained in the PRG BRCH menu (!°%BRCH%):

START … NEXT and START … STEP.

FOR … NEXT and FOR … STEP

DO … UNTIL … END.

WHILE … REPEAT … END.

In addition, the Σ function provides an alternative to definite loop structures for summations.

Using Definite Loop Structures

Each of the two definite loop structures has two variations:

NEXT. The counter increases by 1 for each loop.

STEP. The counter increases or decreases by a specified amount for each loop.

RPL Programming 1-17