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)