#ifdef...#else...#endif
Provides conditional compiling capabilities.
Syntax
#ifdef identifier ... Source code for conditional compile
[#else] ... Source code for false condition
#endif
Parameters
- Identifier
- #Keyword defined by the user which allows the source code defined between ifdef and #else or #endif to be compiled. Thus the identifier acts as the condition for the conditional compile.
Description
#ifdef...#else...#endif allows for the conditional compiling of selected source code. The condition as to whether or not the compile will occur is determined based on the identifier. #ifdef first checks if the specified identifier is currently defined by #define. #The #else statement is optional.
If defined, and the #else statement is not used, the statements between #ifdef and #endif are compiled. #Otherwise, if #else is used, then the statements between #ifdef and #else are compiled.
If not defined, and the #else statement is not used, the statements between #ifdef and #endif are skipped without being compiled. #Otherwise, if #else is used, then the statements between #else and #endif are compiled.
See Also
#define, #ifndef
#ifdef Example
A section of code from a sample program using #ifdef is shown below. In the example below, the printing of the value of the variable A$ will be executed depending on the presence or absence of the definition of the #define DEBUG pseudo instruction. If the #define DEBUG pseudo instruction was used earlier in this source, the Print A$ line will be compiled and later executed when the program is run. However, the printing of the string "The End" will occur regardless of the #define DEBUG pseudo instruction.
' Uncomment next line for Debug mode.
' #define DEBUG
Input #1, A$
#ifdef DEBUG
Print "A$ = ", A$
#endif
Print "The End"