FutureBasic Logo

<<    Index    >> FutureBasic 5

#if   statement



Syntax:
#if condition
  [statementBlock1]
[#else
  [statementBlock2]]
#endif


Description:
You can use the #if statement to conditionally include or exclude selected lines of code from the compiled version of your program. This is useful if you need to maintain two or more slightly different versions of your program; #if allows you to maintain them both within the same source file.
If the condition following #if is evaluated as "true" or non-zero, then the statements in statementBlock1 are included in the compilation and the statements (if any) in statementBlock2 are ignored by the compiler. If the condition is evaluated as "false" or zero, then the statements in statementBlock1 are ignored by the compiler, and the statements (if any) in statementBlock2 are included in the compilation.
The #if statement must be matched by a following #endif statement.

condition must have one of the following forms: constExpr is a "static integer expression." A static integer expression is a valid expression which consists only of:
In particular, it can't contain variables or function references. If you use this form of #if, then the condition will be evaluated as "true" if the expression's value is nonzero.
_symbolicConstant stands for a symbolic constant name.
def _symbolicConstant is evaluated as "true" if the indicated constant was previously defined, regardless of its value.
ndef _symbolicConstant is evaluated as "true" if the indicated constant was not previously defined.

Example:
Because #if can cause lines (including non-executable lines) to be completely ignored by the compiler, you can use it to control such things as the declaration of variables, program labels, constants, and even entire functions.

_myDebugStuff = 0 // 0 or 1
#if _myDebugStuff
 local fn DebugPrint( a as long )
 ...
 end fn
#endif


_dimensions = 3
#if ( _dimensions == 3 )
 def fn Diag!( a, b, c ) = sqr( a*a + b*b + c*c )
#else
 def fn Diag!( a, b ) = sqr( a*a + b*b )
#endif