Table of Contents
1. loop
Repeatedly executes a procedure indefinitely until exit is called.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
(varies) |
Results from procedure executions |
1.3. Description
1.5. Examples
Loop with exit condition
0 {
dup 10 ge { exit } if
dup =
1 add
} loop
pop
% Prints: 0 1 2 3 4 5 6 7 8 9
Reading until condition
file {
read not { exit } if
% Process character
} loop
Infinite server loop
{
% Wait for request
% Process request
% Send response
} loop
1.7. Common Pitfalls
{ (infinite) print } loop % Never stops!
| Stack Growth - Ensure loop body balances stack or it will overflow. |
{ 1 } loop % Stack overflow eventually
| Use External Interrupt - Infinite loops can be broken via implementation-specific external interrupts (e.g., Ctrl-C). |
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
No operand on stack |
[ |
Operand is not a procedure |
1.9. Implementation Notes
-
No iteration limit checked
-
Very lightweight (minimal overhead per iteration)
-
Procedure must contain exit logic
-
Common pattern for server loops