Reference Guide

1-22 RPL Programming
Example:
The following program takes n from the stack, and returns the series of numbers 1, 2, 4, 8, 16, …, n. If n
isn’t in the series, the program stops at the last value less than n.
«
1 SWAP FOR n n n STEP
»
The first n is the local variable declaration for the FOR loop. The second n is put on the stack each iteration of the
loop. The third n is used by STEP as the step increment.
Using Indefinite Loop Structures
The DO  UNTIL  END Structure
The syntax for this structure is
«
DO
loop-clause
UNTIL
test-clause
END
»
DO… UNTIL… END executes the loop-clause sequence repeatedly until test-clause returns a true (nonzero) result.
Because the test-clause is executed after the loop-clause, the loop-clause is always executed at least once.
Syntax Flowchart
UNTIL
END
Body of loop
TEST
Is test
result non-zero?
no
yes
1: test result
test-clause
DO
loop-clause
DO  UNTIL  END Structure
DO starts execution of the loop-clause. UNTIL marks the end of the loop-clause. The test-clause leaves a test
result on the stack. END removes the test result from the stack. If its value is zero, the loop-clause is executed again
— otherwise, execution resumes following END. If the argument of END is an algebraic or a name, it’s
automatically evaluated to a number.
To enter DO  UNTIL  END in a program:
Press
%BRCH%
!
%DO%
.