Previous:Conditional Directives   Main Index   Next:The #ifdef and #ifndef Directives



The #if...#else...#end Directives

The simplest conditional directive is a traditional #if directive. It is of the form...

IF_DIRECTIVE:
#if ( Cond ) TOKENS... [#else TOKENS...] #end

The TOKENS are any number of POV-Ray keyword, identifiers, or punctuation and ( Cond ) is a float expression that is interpreted as a boolean value. The parentheses are required. The #end directive is required. A value of 0.0 is false and any non-zero value is true. Note that extremely small values of about 1e-10 are considered zero in case of round off errors. If Cond is true, the first group of tokens is parsed normally and the second set is skipped. If false, the first set is skipped and the second set is parsed. For example:

 #declare Which=1;

 #if (Which)

   box{0,1}

 #else

   sphere{0,1}

 #end

The box is parsed and the sphere is skipped. Changing the value of Which to 0 means the box is skipped and the sphere is used. The #else directive and second token group is optional. For example:

 #declare Which=1;

 #if (Which)

   box{0,1}

 #end

Changing the value of Which to 0 means the box is removed.



Previous:Conditional Directives   Main Index   Next:The #ifdef and #ifndef Directives