Introduction

Language Structure

IB Statements

File System

Comet 32 Runtime

Index

Conditional Compilation

The Internet Basic compiler contains a conditional compilation feature. With conditional compilation, you can write an Internet Basic source program that includes portions of code that will be compiled only if a symbolic constant has been SET. As a result, you can write one comprehensive source program, but include or exclude specific sections simply by setting a flag in your source program.

Conditional compilation is controlled by the following two compiler directives, which may appear in any section of the Internet Basic source program:

.IF
.ENDIF

In addition, the following directives extend the capability of the conditional compilation feature:

.IFDEF
.IFNDEF
.ELSE

The Basic Structure of a Conditional Source Segment

Within an Internet Basic source program, specific lines can be identified as conditional source segments. A conditional source segment begins with the .IF directive (or one of its alternatives) and ends with the .ENDIF directive, as follows:

.IF symbolic-constant

(conditional source segment)

.ENDIF

The Internet Basic compiler will compile the conditional source segment only if the symbolic constant has been SET to a non-zero value.

Example:

In the following example, the symbolic constant named ABC is set to a non-zero value. When the compiler reaches the .IF directive, it compiles the subsequent lines up through the .ENDIF directive. Note, however, that if ABC was either not defined (not SET) or contained a value of 0, the compiler would skip the conditional source segment.

  SET ABC = 1       ! set the symbolic constant to a non-zero value

  .IF ABC           ! beginning of conditional source segment

   Internet Basic code segment

  .ENDIF            ! end of conditional source segment

The .ELSE Directive

Another useful feature is the .ELSE directive. This provides for the conditional compilation of alternative code segments, as follows:

.IF symbolic-constant

Internet Basic code segment 1

.ELSE

Internet Basic code segment 2

.ENDIF

The .IF directive tests the value of the symbolic constant. If it contains a non-zero value, the first code segment is compiled (and the second segment is not). If the symbolic constant contains a value of 0 or is not SET, only the second code segment is compiled.

Example:

  SET ABC=0            ! symbolic constant = 0
                       ! therefore, compile code segment 2
  .IF ABC
  (segment 1)

  .ELSE
  (segment 2)

  .ENDIF

The .IFDEF and .IFNDEF Directives

There are two variations to the .IF directive. They are explained in the following chart:

Directive Description
.IFDEF symbolic-constant Compiles the code segment only if the symbolic constant has been defined (via the SET) statement, regardless of its value. Otherwise, skips the code segment.
.IFNDEF symbolic-constant Compiles the code segment only if the symbolic constant has not been defined or has been UNSET.

The UNSET Directive

To facilitate the manipulation of symbolic constants for conditional compilation purposes, the Internet Basic language includes the UNSET directive. Here is the syntax for this directive:

Syntax:	UNSET symbolic-constant

The UNSET directive clears the definition of the symbolic constant (i.e., "un-defines" it). This directive is particularly useful when working with the .IFDEF and .IFNDEF directives.

Example:

  UNSET ABC         ! un-define the symbolic constant named ABC