for  ( n -- )

published: 28 January 2023 / updated 28 January 2023

Lire cette page en français

 

vocabulary: forth

Marks the start of a loop for .. 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.

Example:

: loop ( ---) 
    10 for 
        r@ . cr  \ display loop index 
    next 
  ;