REPEAT, will repeat itself forever unless you explicitly exit the loop:
//Runs forever
REPEAT:
// Do stuff
END.
To exit the loop you can use the LEAVE
keyword. With or without a label. Without a label LEAVE
will always effect the current loop. With a name you can specify what loop to LEAVE
.
/* Without a label */
REPEAT:
//Do stuff
IF TRUE THEN LEAVE.
END.
/* With a label */
loopLabel:
REPEAT:
//Do stuff
IF <somecondition> THEN LEAVE loopLabel.
END.
/* Two nested REPEATS */
DEFINE VARIABLE i AS INTEGER NO-UNDO.
loopLabelOne:
REPEAT:
loopLabelTwo:
REPEAT:
i = i + 1.
IF RANDOM(1,100) = 1 THEN LEAVE loopLabelTwo.
IF RANDOM(1,100) = 1 THEN LEAVE loopLabelOne.
END.
IF RANDOM(1,100) = 1 THEN LEAVE loopLabelOne.
END.
DISPLAY i.