如果...那麼... 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.