Progress
Programming
Handbook


&IF, &THEN, &ELSEIF, &ELSE, and &ENDIF Directives

You use these directives to set logical conditions when compiling blocks of code. This is the syntax for these directives:

SYNTAX
&IF expression &THEN 
   . 
   . 
   . 
[ &ELSEIF expression &THEN ] ... 
   . 
   . 
   . 
[ &ELSE ] 
   . 
   . 
   . 
&ENDIF 
                                 . 
                                                             . = block of source code 
                                                             . 

The expression can contain the following elements: preprocessor name references, the operators listed in Table 8–2, the Progress functions listed in Table 8–3, and the DEFINED( ) preprocessor function. The DEFINED( ) function indicates whether a preprocessor name is defined. For more information on the DEFINED( ) function, see the "DEFINED( ) Preprocessor Function" section.

When the preprocessor evaluates an expression, all arithmetic operations are performed with 32-bit integers. Preprocessor name references used in arithmetic operations must evaluate to integers.

When encountering an &IF directive, the preprocessor evaluates the expression that immediately follows. This expression can continue for more than one line; the &THEN directive indicates the end of the expression. If the expression evaluates to TRUE, then the block of code between it and the next &ELSEIF, &ELSE, or &ENDIF is compiled. If the expression evaluates to FALSE, the block of code is not compiled and the preprocessor proceeds to the next &ELSEIF, &ELSE, or &ENDIF directive. No include files referenced in this uncompiled block of code are included in the final source. You can nest &IF directives.

Table 8–1 indicates how preprocessor expressions are evaluated.

Table 8–1: Preprocessor Expressions 
Type of Expression
TRUE
FALSE
LOGICAL
TRUE
FALSE
CHARACTER
Non-empty
Empty
INTEGER
Non-zero
0
DECIMAL
Not supported
Not supported

The expression that follows the &ELSEIF directive is evaluated only if the &IF expression tests FALSE. If the &ELSEIF expression tests TRUE, then the block of code between it and the next &ELSEIF, &ELSE, or &ENDIF directive is compiled. If the &ELSEIF expression tests FALSE, the preprocessor proceeds to the next &ELSEIF, &ELSE, or &ENDIF directive.

The block of code between the &ELSE and &ENDIF directives is compiled only if the &IF expression and the &ELSEIF expressions all test FALSE. If there are no &ELSEIF directives, the block of code is compiled if the &IF expression tests FALSE.

Once any &IF or &ELSEIF expression evaluates to TRUE, no other block of code within the &IF ... &ENDIF block is compiled.

The &ENDIF directive indicates the end of the conditional tests and the end of the final block of code to compile.

Table 8–2: Preprocessor Operators
Operator
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
=
Equality
<>
Inequality
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
AND
Logical and
OR
Logical or
NOT
Logical not
BEGINS
Compares the beginning letters of two expressions
MATCHES
Compares two character strings

These operators have the same precedence as the regular Progress 4GL operators.

Table 8–3: Functions Allowed in Preprocessor Expressions 
ABSOLUTE
LC
RIGHT–TRIM
ASC
LENGTH
RANDOM
DATE
LIBRARY
REPLACE
DAY
LOG
ROUND
DECIMAL
LOOKUP
SQRT
ENCODE
MAXIMUM
STRING
ENTRY
MEMBER
SUBSTITUTE
ETIME
MINIMUM
SUBSTRING
EXP
MODULO
TIME
FILL
MONTH
TODAY
INDEX
NUM–ENTRIES
TRIM
INTEGER
OPSYS
TRUNCATE
KEYWORD
PROPATH
WEEKDAY
KEYWORDALL
PROVERSION
YEAR
LEFT–TRIM
R–INDEX

You can use any of these expressions within a preprocessor expression; they are evaluated at compile time.


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