RPL Programming 1-17
Program: Comments:
"!
#!@!
"
Defines local variable y.
Starts the defining procedure.
OBD<!
@!:P2<!H!DBM<!
:;<=!@!+D:K+!D:L!!
<=4!
@!:P2<!Q!DBM<!
:;<=!@!+E6D:+!D:L!
<=4!
@!:P2<!R!DBM<!
:;<=!@!+2KL>+!D:L!
<=4
Starts the case structure.
Case 1: If the argument is a string, stores it in STR.
Case 2: If the argument is a list, stores it in LIST.
Case 3: If the argument is a program, stores it in
PROG.
<=4!
»
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.
The START … NEXT Structure
The syntax for this structure is
! «!…!start finish!START!loop-clause!NEXT…!»
START … NEXT executes the loop-clause sequence of commands one time for each number in the range start
to finish. The loop-clause is always executed at least once.