Tutorial by Examples

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...
The CASE-statement is a lot more strict than the IF/ELSE-conditional. It can only compare a single variable and only equality, not larget/smaller than etc. DEFINE VARIABLE c AS CHARACTER NO-UNDO. CASE c: WHEN "A" THEN DO: RUN procedureA. END. WHEN "B" ...
IF THEN ELSE can also be used like a function to return a single value. This is a lot like the ternary ?-operator of C. DEFINE VARIABLE i AS INTEGER NO-UNDO. DEFINE VARIABLE c AS CHARACTER NO-UNDO. /* Set c to "low" if i is less than 5 otherwise set it to "high" c...

Page 1 of 1