Progress
Language Tutorial
for Character


Using the IF Statement

The IF statement allows you to test for a condition and then execute code if the expression is TRUE. The ELSE option allows you to specify a second block of code to execute if the expression is FALSE. This is the syntax.

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

The code for either the THEN or ELSE branch can be either a statement or a block, as this example shows:

      FOR EACH Customer:
          IF Balance < 10000 THEN
/*1*/            DO:
                  Small-Accounts = Small-Accounts + 1.
                  Small-Total = Small-Total + Balance.
                 END.
           ELSE
/*2*/          DO:
                Big-Accounts = Big-Accounts + 1.
                Big-Total = Big-Total + Balance.
               END.
       END.

      DISPLAY "There are" Small-Accounts "accounts under $10,000."
              "The total outstanding balance is" Small-Total SKIP(1).

      DISPLAY "There are" Big-Accounts "accounts over $10,000."
              "The total outstanding balance is" Big-Total. 

The block at point 1 executes when the expression is TRUE, while the block at point 2 executes when the expression is FALSE.


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