RPL Programming 1-23
Program: Comments:
"!
4L!
+&+!6=OK!
G!.!+Z+!D:L'!
5=:6E!
Z!3888!9!
<=4!
Z!&
1
Starts the defining procedure.
Starts the loop-clause.
Increments the counter by 1. (See
Using Loop
Counters.)
Calculates c × n and adds the product to s.
Starts the test-clause.
Repeats loop until s > 1000.
Ends the test-clause.
Puts s and c on the stack.
Ends the defining procedure.
»
The WHILE … REPEAT … END Structure
The syntax for this structure is
! «!…!WHILE!test-clause!REPEAT!loop-clause!END!…!»
WHILE … REPEAT … END repeatedly evaluates test-clause and executes the loop-clause sequence if the test
is true. Because the test-clause is executed before the loop-clause, the loop-clause is not executed if the test is
initially false.
Syntax Flowchart
REPEAT
END
TEST
Is test
result non-zero?
no
yes
1: test result
loop-clause
WHILE
test-clause
Body of loop
WHILE … REPEAT … END Structure
WHILE starts execution of the test-clause, which returns a test result to the stack. REPEAT takes the value from
the stack. If the value is nonzero, execution continues with the loop-clause-otherwise, execution resumes
following END. If the argument of REPEAT is an algebraic or a name, it's automatically evaluated to a number.