DO var start TO 完成 BY 步驟
此迭代將值從起點更改為結束,可選地按每個步驟的指定值更改。預設更改為 1。
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 10 TO 15:
DISPLAY i WITH FRAME x1 6 DOWN .
DOWN WITH FRAME x1.
END.
結果:
---------------i
10
11
12
13
14
15
你也可以迭代日期:
DEFINE VARIABLE dat AS INTEGER NO-UNDO.
DO dat = TODAY TO TODAY + 3:
END.
超過小數。但是你最有可能想要使用 BY
- 否則 INTEGER
會做得很好……
DEFINE VARIABLE de AS DECIMAL NO-UNDO.
DO de = 1.8 TO 2.6 BY 0.2:
DISPLAY "Value" de.
END.
使用 BY
為負數,你也可以從較高的值變為較低的值:
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 5 TO 1 BY -1:
END.
表示式將被測試,直到它不再符合。這使得計數器在迴圈結束後更高(如果向上移動)或更低(如果向下移動):
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 5 TO 1 BY -1:
END.
MESSAGE i. // Will message 0
另一個例子:
DEFINE VARIABLE da AS DATE NO-UNDO.
DISPLAY TODAY. //17/02/06
DO da = TODAY TO TODAY + 10:
END.
DISPLAY da. //17/02/17 (TODAY + 11)