Example: The following program calculates n + 2n +3n + … for a value of n. The program stops when the sum exceeds 1000, and returns the sum and the coefficient of n.
Program: | Comments: |
|
|
« |
|
DUP 1 | Duplicates n, stores the value into n and |
→ n s c | s, and initializes c to 1. |
« | Starts the defining procedure. |
DO | Starts the |
'c' INCR | Increments the counter by 1. (See Using |
| Loop Counters.) |
n * 's' STO+ | Calculates c × n and adds the product to |
| s. |
UNTIL | Starts the |
s 1000 > | Repeats loop until s > 1000. |
END | Ends the |
s c | Puts s and c on the stack. |
» | Ends the defining procedure. |
» |
|
|
|
RPL Programming