FOR NEXT ENDIT AFT
for ( n ---)
Marks the start of a loop for .. next
Example:
: loop ( ---) 10 for r@ . cr \ display loop index next ;
The for .. next
loop accepts a single single precision argument before
for
. The loop index can be retrieved with the word r@
inside the for .. next
loop.
The loop index value will take all values between n-1 and 0 decreasing.
In our example, for the starting value 10, the loop index will take all values between 9 and 0, or 10 values in total.
next ( ---)
Marks the end of a loop for .. next
endit
Set the loop index to 0, which will cause the loop to end when executed
of next
.
aft ( a -- a A )
Jumps to THEN in a FOR-AFT-THEN-NEXT loop the first time through. It compiles a BRANCH address literal and leaves its address field on stack. This address will be resolved by THEN. It also replaces address A left by FOR by the address of next token so that NEXT will compile a DONEXT address literal to jump back here at run time.