Previous:The #switch, #case, #range and #break Directives Main Index Next:User Message Directives

#### The #while...#end Directive

The `#while` directive is a looping feature that makes it easy to place multiple objects in a pattern or other uses.

WHILE_DIRECTIVE:
`
  #while (
` Cond `)` TOKENS... `#end`

The TOKENS are any number of POV-Ray keyword, identifiers, or punctuation marks which are the body of the loop. The `#while` directive is followed by a float expression that evaluates to a boolean value. 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. The parentheses around the expression are required. If the condition is true parsing continues normally until an `#end` directive is reached. At the end, POV-Ray loops back to the `#while` directive and the condition is re-evaluated. Looping continues until the condition fails. When it fails, parsing continues after the `#end` directive. Note it is possible for the condition to fail the first time and the loop is totally skipped. It is up to the user to insure that something inside the loop changes so that it eventually terminates. Here is a properly constructed loop example:

     #declare Count=0;

     #while (Count < 5)

      object{MyObject translate x*3*Count}

      #declare Count=Count+1;

     #end

This example places five copies of `MyObject` in a row spaced three units apart in the x-direction.

Previous:The #switch, #case, #range and #break Directives Main Index Next:User Message Directives