如果...那么... ELSE 声明

IF THEN ELSE 语句中,结果可以是单个语句:

DEFINE VARIABLE i AS INTEGER     NO-UNDO.

IF i = 0 THEN
    MESSAGE "Zero".
ELSE 
    MESSAGE "Something else".

或者一个块,例如通过添加 DO-block:

DEFINE VARIABLE i AS INTEGER     NO-UNDO.

IF i = 0 THEN DO:
    RUN procedure1.
    RUN procedure2.
END.
ELSE DO: 
    RUN procedure3.
    RUN procedure4.
END.

可以使用 ELSE IF 语法嵌套几个 IF 语句:

DEFINE VARIABLE i AS INTEGER     NO-UNDO.

IF i = 0 THEN DO:
    RUN procedure1.
    RUN procedure2.
END.
ELSE IF i = 1 THEN DO:
    RUN procedure3.
    RUN procedure4.

END.
ELSE DO: 
    RUN procedure5.
    RUN procedure6.
END.

ELSE 部分不是强制性的:

DEFINE VARIABLE l AS LOGICAL     NO-UNDO.

l = TRUE.

IF l = TRUE THEN DO:
    MESSAGE "The l variable has the value TRUE" VIEW-AS ALERT-BOX.
END.

IF / ELSE IF 可以比较几种条件,有或没有内部连接。这使你可以通过以下几种方式释放代码:

DEFINE VARIABLE i AS INTEGER     NO-UNDO.
DEFINE VARIABLE l AS LOGICAL     NO-UNDO.

IF i < 30 OR l = TRUE THEN DO:
    
END.
ELSE IF i > 30 AND l = FALSE OR TODAY = DATE("2017-08-20") THEN DO:

END.
ELSE DO:
    MESSAGE "I dont really know what happened here".
END.