LOOP instruction |
LOOP
block of instructions which are executed repeatedly
END
LOOP is a more general looping instruction than WHILE and UNTIL. It loops between the LOOP and END lines indefinitely unless a BREAK instruction is executed.
Description
LOOP repeatedly executes the block of instructions between the LOOP and END LOOP statements. You decide where and when to execute BREAK instructions to terminate the loop. BREAK is the only way out of a LOOP. A NEXT will jump back up to the top of the loop from wherever it is executed.
LOOP is most valuable when you make the continuation decision in the middle of the block, rather than at the beginning or end. It is good programming practice to use WHILE or UNTIL where possible, since they make it easier to follow the program flow.
Example
loop
menu "What Next?"
choice "Specify Model"
source specify.src
choice "Estimate Model"
source estimate.src
choice "Do Forecasts"
source forecast.src
choice "Quit"
break
end menu
end loop
This repeatedly offers a set of choices, until the person using the program selects Quit. The BREAK after the Quit choice breaks control out of the loop.
Copyright © 2025 Thomas A. Doan