重複

REPEAT 將永遠重複,除非你明確退出迴圈:

//Runs forever
REPEAT:
    // Do stuff
END.

要退出迴圈,你可以使用 LEAVE 關鍵字。有無標籤。如果沒有標籤,LEAVE 將始終影響當前迴圈。使用名稱,你可以指定 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.