GENERATE/PREV.gifGENERATE/NEXT.gif

While and Do Loops

The while loop and do loop are simple variants of one another. The syntax is:

do <expr> while <expr>

while <expr> do <expr>

Both are loops that repeat the do <expr> as long as the while <expr> evaluates to the value true. The do form evaluates the do <expr> at least once, evaluating the test expression at the end of each loop. The while form evaluates the test-expression at the start of each loop and so may not loop at all.

They both return as their value the result of the do <expr> from the last successful loop iteration. The while form may return the value undefined if the loop test returns false immediatley.

Examples:

while x > 0 do

(

print x

x -= 1

)

 

do print (read_value f) while not eof f