In the IF THEN ELSE
statement the result can be either a single statement:
DEFINE VARIABLE i AS INTEGER NO-UNDO.
IF i = 0 THEN
MESSAGE "Zero".
ELSE
MESSAGE "Something else".
Or a block, for instance by adding a 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.
Several IF
-statements can be nested with the ELSE IF
-syntax:
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.
The ELSE
-part is not mandatory:
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.
The IF
/ELSE IF
can compare several conditionals, with or without internal connections. This leaves you free to mess up your code in several ways:
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.