Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    Conditional Statements -
Deutsch Deutsch

Home
- POV-Ray Tutorial

  - Conditional
    Statements

  Branching
   >#if(...)... #else ... #end
    - in loops
    - in macros
    - in animations
    - turning on/off of parts
    #switch(...) #case(..) ...
            #range(..) ... #end
    - selection by tables

  Check for Existence
    #ifdef(...) #ifndef(...)
    - Check in include files
    - Defaults in include files

  Loops
 Prechecked, Postchecked,
 Count-controlled, Early-Exit
    #while(...)... #end
    #for(...)... #end
    - Samples:
    - Loops with POV-Ray
    - Loops, Sine, Cosine
    - Random with POV-Ray
                                       

Conditional Statements for Branching

In the scenery description language (SDL) of POV-Ray there are 2 different structures, which allow us to realizise conditional statements as known from all programming languages:

Simple Branching
#if-statement

(If ... then ... else ...)
Multible Branching
#switch-statement

(Branching by different switch values)
Syntax in POV-Ray:
#if (Condition)
 ... statements1
#else // (optional)
 ... statements2
#end 
      
Syntax in POV-Ray:
#switch (Switch_Variable)
#case (Switch_Value1)
 ...  statements
#break
#case (Switch_Value2)
 ...  statements
#break
#range (Switch_Value_Start,Switch_Value_End)
 ...  statements
#break
#else // (optional)
 ...  statements
#break
#end // end of #switch
Equivalent structures in other programming languages:
IF <condition>
THEN
   <actions>
ELSE
   <alternative actions>
ENDIF
 
SWITCH (someChar) {
  CASE 'a': <actionOn "a">;
    BREAK;
  CASE 'x': <actionOn "x">;
    BREAK;
  CASE 'y':
  CASE 'z': <actionOn "y"and"z">;
    BREAK;
  DEFAULT: <actionOnNoMatch>;
}
JavaScript:
if (condition) {
    (action) ;
} 
if (condition) { (actionOnCondition) ; } else { (actionOtherwise) ; return; }
JavaScript:
switch (variable) {
  case "1":
     (actionOn1);
    break;
  case "2":
    (actionOn2);
    break;
  default:
    (actionOnDefault);
    break;
}
Note: While using float numbers for the conditions or cases you should be aware of the fact that extremely small values of about 1e-10 are considered zero in case of round off errors.
top
© Friedrich A. Lohmüller, 2010
homepage:http://www.f-lohmueller.de
 
Visitors:
(since May-1999)
Thanks for your visit!