Start loop

Purpose: Loop execution based on a condition.

 start-loop  [ repeat <repeat> ] \
     [ use <loop counter> \
         [ start-with <start with> ] [ add <add> ] ]

     <any code>

 end-loop

start-loop will execute code between start-loop and "end-loop" clauses certain number of times based on a condition specified and the usage of continue-loop and break-loop, which can be used in-between the two.

<repeat> number (in "repeat" clause) specifies how many times to execute the loop (barring use of continue-loop and break-loop).

<loop counter> (in "use" clause) is a number that by default starts with value of 1, and is incremented by 1 each time execution loops back to start-loop, unless "start-with" and/or "add" clauses are used. The end value of <loop counter> (just outside "end-loop") is the first value past the last loop.

If <start with> (in "start-with" clause) is used, that's the initial value for <loop counter> (instead of the default 1), and if <add> is specified (in "add" clause), then <loop counter> is incremented by <add> each time execution loops back to start-loop (instead of the default 1). <add> can be positive or negative.

If either of "start-with" or "add" clauses is used, then "use" must be specified.
Examples
Print numbers 0 through 19:
 start-loop repeat 20 use p start-with 0
     print-out p
     @
 end-loop

A loop that is controlled via continue-loop and break-loop statements, displaying numbers from 1 through 30 but omitting those divisible with 3:
 set-number n
 set-number max = 30
 start-loop
     set-number n add 1
     if-true n every 3
         continue-loop
     end-if
     if-true n greater-than max
         break-loop
     end-if
     print-out n
 end-loop

See also
Program flow
break-loop  
call-handler  
code-blocks  
continue-loop  
do-once  
exit-handler  
if-defined  
if-true  
quit-process  
return-handler  
start-loop  
See all
documentation


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.