Progress
Language Reference


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

Interfaces
OS
SpeedScript
All
All
Yes

These directives set logical conditions for the inclusion of blocks of code to compile.

SYNTAX

&IF expression &THEN
  block
[ &ELSEIF expression &THEN
  block ] ...
[ ELSE
  block ]
&ENDIF 

expression

An expression that can contain preprocessor name references, the operators listed in
Table 6, the Progress functions listed in Table 7, and the DEFINED preprocessor function.

When it encounters 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 block of code are included in the final source. You can nest &IF directives.

The expression that follows the &ELSEIF directive is evaluated only if the &IF expression tests false. If the &ELSEIF expression tests TRUE, 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 5 shows how preprocessor expressions are evaluated.

Table 5: Preprocessor Expressions 
Type of Expression
TRUE
FALSE
LOGICAL
TRUE
FALSE
CHARACTER
non-empty
empty
INTEGER
non-zero
0
DECIMAL
not supported
not supported

Table 6 lists the operators supported within preprocessor expressions. These operators have the same precedence as the regular Progress 4GL operators.

Table 6: 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 strings

Table 7 lists the Progress 4GL functions supported within preprocessor expressions.

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

NOTE

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

SEE ALSO

&GLOBAL-DEFINE Preprocessor Directive, &SCOPED-DEFINE Preprocessor Directive, &UNDEFINE Preprocessor Directive


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