80 of 172
ZBasic Language Reference 73 ZX Microcontroller Family #ifdef EXPERIMENTAL ver = "X006" #else ver = "V1.4" #endif An alternate form of conditional directive allows you to specify an expression involving conditional identifiers and integer or string literals, the Boolean value of which determines whether the code within the conditional block is processed normally or not. #if <expression> <other-text> #elseif <expression> <other-text> #else <other-text> #endif The <expression> element may be any legal ZBasic expression involving constants, conditional identifiers, ZBasic operators and ZBasic System Library functions that can be evaluated at compile time. The usual type-compatibility rules apply, e.g., you cannot add an integral value and a string value. Additionally, the special operator defined() may be used in a conditional expressions. The parameter to the defined() operator should be an identifier and the result will be non-zero or zero depending on whether the identifier is defined or not. Examples #if defined(EXPERIMENTAL) Debug.Print "Experimental version" #endif #if defined(Pin.RedLED) Call PutPin(Pin.RedLED, zxOutputLow) #endif The #elseif clause in the conditional construction may appear zero or more times. The #else clause may appear at most once. The <other-text> element represents arbitrary text and may contain other conditional constructs. There is no practical limit on the nesting of conditionals. Examples #if Version >= 23 #ifdef EXPERIMENTAL ' prepare the external circuitry and activate it Call TestSetup(i) Call PutPin(12, j) #endif #endif #if (Version >= 23) And (EXPERIMENTAL <> 0) ' prepare the external circuitry and activate it Call TestSetup(i) Call PutPin(12, j) #endif The two examples above have the same effect. Conditional identifiers may be used in definitions, statements, and expressions as if they were constants defined using the Const definition (but the converse is not true).