Progress
Language Reference


IF...THEN...ELSE Statement

Interfaces
OS
SpeedScript
All
All
Yes

Makes the execution of a statement or block of statements conditional. If the value of the expression following the IF statement is TRUE, Progress processes the statements following the THEN statement. Otherwise, Progress processes the statements following the ELSE statement.

SYNTAX

IF expression THEN { block | statement }
  [ ELSE { block | statement } ] 

expression

A constant, field name, variable name, or expression whose value is logical (TRUE or FALSE). The expression can include comparisons, logical operators, and parentheses.

THEN

Describes the block statement to process if the expression is TRUE.

block

The block statement that contains the code you want to process if expression is TRUE. See the DO Statement, FOR Statement, and REPEAT Statement reference entries for more information. If you do not start a block, you can process just one statement after the IF keyword or the ELSE keyword.

Any block or blocks you use in an IF . . . THEN . . . ELSE statement can contain other blocks or other IF . . . THEN . . . ELSE statements.

statement

A single Progress statement. The statement can be another IF . . . THEN . . . ELSE statement. If you want to use more than one statement, enclose those statements in a DO, FOR EACH, or REPEAT block.

ELSE

Describes the block statement to process if the expression is FALSE or unknown (?). The ELSE option is not required.

EXAMPLE

The r-ifelss.p procedure creates a report in a file that lists customers whose orders have been shipped but who have not paid for those orders.

r-ifelss.p
DEFINE VARIABLE ans AS LOGICAL.
DEFINE STREAM due.

OUTPUT STREAM due TO ovrdue.lst.
   DISPLAY STREAM due
           "Orders shipped but still unpaid as of" TODAY SKIP(2)
           WITH NO-BOX NO-LABELS CENTERED FRAME hdr PAGE-TOP.

FOR EACH order WITH FRAME oinfo:
    FIND customer OF order NO-LOCK.
    DISPLAY order-num name order-date promise-date ship-date.
    IF ship-date = ? THEN DO:
        IF promise-date = ? THEN DO:
           MESSAGE "Please update the promise date.".
           REPEAT WHILE promise-date = ?:
              UPDATE promise-date WITH FRAME oinfo.
           END.
        END.
        ans = FALSE.
        MESSAGE "Has this order been shipped?" UPDATE ans.
        IF ans
        THEN REPEAT WHILE ship-date = ?:
           UPDATE ship-date WITH FRAME oinfo.
        END.
    END.
    ELSE DO:
        ans = TRUE.
        MESSAGE "Has this order been paid?" UPDATE ans.
        IF NOT ans THEN DO:
            DISPLAY STREAM due order-num TO 14 name AT 18
                    order-date AT 42 ship-date AT 54
                    WITH NO-BOX DOWN FRAME unpaid.
        END.
    END.
END.
OUTPUT STREAM due CLOSE. 

First, the procedure writes report headers to the ovrdue.lst file. Next, the outer FOR EACH block reads each of the orders using a DISPLAY statement to display information on each order. If there are no values in the ship-date and promise-date fields, the procedure prompts you to enter a promise date. The procedure then prompts if the order has been shipped. If it has, supply a ship date.

If there is a ship date and a promise date for an order, the procedure prompts if the order has been paid for. If not, the procedure displays the order information to the file.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095