#IF ... #ENDIF Preprocessor Directive

Example   See Also

Conditionally includes source code at compile-time.

Syntax

#IF nExpression1 | lExpression1
  Commands
[#ELIF nExpression2 | #ELIF lExpression2
  Commands
   ...
#ELIF nExpressionN | #ELIF lExpressionN
  Commands]
[#ELSE
  Commands]
#ENDIF

Arguments

#IF nExpression1 | lExpression1
Commands

nExpression1 specifies the numeric expression that is evaluated.

#ELIF nExpression2 | #ELIF lExpression2
Commands


...

#ELIF nExpressionN | #ELIF lExpressionN
Commands

If nExpression1 is 0 or lExpression1 is false (.F.), the #ELIF directives are evaluated. The first #ELIF expression nExpression2 or lExpression2, if present, is evaluated. If nExpression2 is nonzero or lExpression2 is true (.T.), the commands following #ELIF are included in the compiled code. The #IF ... #ENDIF structure is exited, and the first program line following #ENDIF is then compiled.

If nExpression2 is 0 or lExpression2 is false (.F.), the commands following #ELIF are not included in the compiled code. The next #ELIF directive is evaluated.

#ELSE Commands

If no #ELIF directives are included, or if those that are included evaluate to 0 or false (.F.), the presence or absence of #ELSE determines whether any additional commands are included in the compiled code:

#ENDIF

Indicates the end of the #IF statement.

Remarks

#IF ... #ENDIF can improve the readability of source code, reduce compiled program size, and, in some cases, improve performance.

When the #IF ... #ENDIF structure is compiled, successive logical or numeric expressions within the structure are evaluated. The evaluation results determine which set of Visual FoxPro commands (if any) are included in the compiled code.