Skip to content

#ENDIF Compiler Directive

Purpose

The #EndIf command allows you to specify conditionally compiled code based on an expression that is evaluated at compile-time.

Syntax

#If {expression}
    {code to compile if expression True}
#Else
    {code to compile if expression False}
#EndIf

Argument Explanation

  • expression: Is any valid Boolean compile-time expression (see below).

Compile-Time Boolean Expressions Syntax

Compile-time Boolean expressions have a very simple syntax as follows:

( {operand} {Boolean-operator} {operand} )

Argument Explanation

  • operand: Is one of:

    • An Integer token, e.g., 1, 2, |CI100.
    • A hex token, e.g., $40000000.
    • An Integer compile-time variable, e.g., !z.
    • Command macro symbol, e.g., !0 (number of arguments).
    • Another Boolean expression, e.g., (!q > 100).
  • operator: Is one of >, <, =.

What It Does

If expression has a value other than zero, the true command lines will be included in the compiled program. Otherwise, the false command lines will be included. For example:

#Command Show_Arguments
#If (!0 > 0)
    Show 'There are !0 arguments'
#Else
    Show 'No arguments'
#EndIf
#EndCommand

This will generate only one compiled line: the first Show if there are any arguments and the second Show if there are not.

There must be an #EndIf for every #If, but the #Else is optional.

If we wanted to have debugging statements in our program that could be included or excluded based on a single statement, we could use an integer variable g that would be true (1) for debug mode and false (0) for runtime mode.

#SET G$ TRUE

(statements generating value for giTestvar)

#If !g
    Show 'TEST VARIABLE=' giTestvar
#EndIf

This example shows the debug flag initialized to true, followed by program command lines which, among other things, generate a value for variable giTestvar. When the debug flag is set to true, the value of giTestvar will be displayed after the legend TEST VARIABLE=. When the program is debugged, the #SET line can be rewritten to set the debug flag to false, and when the file is compiled, the lines triggering debugging statements will not be included.