条件编译示例
示例 1: 从源外部导入布尔值编译变量并对其进行测试
假设 DEFINE (DEBUG) 生效。 在这种情况下, DEBUG 是指参数值为 B '1' 的类别布尔值的编译变量。
>>DEFINE DEBUG AS PARAMETER
. . .
>>IF DEBUG IS DEFINED
display “DEBUG: debugging mode is on”
>>END-IF示例 2: 从源外部导入数字变量值并对其进行测试
假定 DEFINE (VAR1=10) 生效:
>>DEFINE VAR1 AS PARAMETER
. . .
>>DEFINE VAR2 AS VAR1 + 2
. . .
>>IF VAR2 < 12
compute x = x + 1 *> this code should NOT be included
>>ELSE
compute x = x – 1 *> this code should be included
>>END-IF示例 3: 将格式 1 EVALUATE 伪指令与数字编译变量配合使用
>>DEFINE VAR1 AS 6
>>DEFINE VAR2 AS 1
. . .
>>EVALUATE VAR1
>>WHEN VAR2 + 2
compute x = x + 1 *> this code should NOT be included
>>WHEN 4 THRU 8
compute x = x – 1 *> this code should be included
>>WHEN OTHER
compute x = x * 2 *> this code should NOT be included
>>END-EVALUATE示例 4: 将格式 2 EVALUATE 伪指令与字母数字编译变量配合使用
>>DEFINE VAR1 AS 'MOO'
. . .
>>EVALUATE TRUE
>>WHEN VAR2 IS DEFINED
compute x = x + 1 *> this code should NOT be included
>>WHEN VAR1 IS EQUAL TO 'GOO' OR VAR1 IS EQUAL TO 'MOO'
compute x = x – 1 *> this code should be included
>>END-EVALUATE示例 5: 在 DEFINE 伪指令中使用 OVERRIDE 和 OFF
>>DEFINE VAR AS 12
. . .
>>DEFINE VAR OFF
. . .
>>IF VAR IS DEFINED
compute x = x + 1 *> this code should NOT be included
>>ELSE
compute x = x - 1 *> this code should be included
>>END-IF
. . .
>>DEFINE VAR AS 16
. . .
>>DEFINE VAR AS VAR - 2 OVERRIDE
. . .
>>IF VAR IS EQUAL TO 16
compute x = x + 1 *> this code should NOT be included
>>ELSE
compute x = x - 1 *> this code should be included
>>END-IF示例 6: 一般使用布尔字面值和编译变量
>>DEFINE B1 B'1' *> B1 is category boolean
>>DEFINE B2 B'0' *> B2 is category boolean
. . .
>>IF B1 AND B2
display “Both B1 and B2 are true” *> not included
>>ELSE
>>IF B1
display “Only B1 is true” *> included
>>ELSE
>>IF B2
display “Only B2 is true” *> not included
>>ELSE
display “Neither B1 nor B2 is true” *> not included
>>END-IF
>>END-IF
>>END-IF