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 .. #end
    - selection by tables

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

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

Conditional Statements for Loops

In the scenery description language (SDL) of POV-Ray there is a loop structure, which allow us to realizise all loop types known from programming languages:


Realization in POV-Ray
Types of Loops
Other
Programming Languages
#while (condition)
 ... statements
#end 
Prechecked Loop
"While Loop"

WHILE (
condition)
DO
  statements
END
JavaScript:

while (condition) {
  (action);
}
   

 ... statement1 
#while (Inverted condition)
 ... statements
#end 
Postchecked Loop
"Repeat Loop"

REPEAT
  statements
UNTIL (
condition)
END
JavaScript: "do-while"

do {
  (action);
} while (condition);
   
With #for loop:(since POV-Ray 3.7 beta37)
#for (Variable, Start, End[, Step])
   // step optional, default = 1
 ... statements
#end 
With #while loop:
#local Nr = start value;
#local NrEnd = end value;
#local Step = stepsize;
#while (Nr < NrEnd +Step)
 ... statements
#local Nr = Nr + Step;
#end 
Count-controlled loop
"For Loop"

FOR (variable)=(start value) TO (end value)
STEP
stepsize
DO
  statements
NEXT
JavaScript:

for (init; test; continue)
   (action);
   
With #for loop:(since POV-Ray 3.7 beta37)
#for (Identifier, Start, End[, Step])
   // step optional, default = 1
   #if(condition)
      #break // terminate loop early
   #end
   ... statements
#end 
With #while loop:
#local Identifier = start value;
#local End = end value;
#local Step = stepsize;
#while (Identifier < End +Step)
 ... statements
  #if  (condition)
  #local Identifier = NrEnd 
  #end 
#local Identifier = Identifier + Step;
#end 
Early exit from a for loop
"Early Exit Loop"

FOR (variable)=(start value) TO (end value)
STEP
stepsize
DO
  statements
  IF (
condition)
  variable : = end value ;
  END IF
NEXT
JavaScript:

while (condition) {
  if (condition)
    break;
  (action);
}
   

Note: While using float numbers for the conditions 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:www.f-lohmueller.de