POV-Ray : Documentation : 1.3.9.2 How does a single while-loop work?
  POV-Ray 3.6 Documentation Online View  
1.3.9.1 What a while-loop is and what it is not   1.3.9.3 How do I make a while-loop?

1.3.9.2 How does a single while-loop work?

The while-loop works like this:

  1. If the condition between the parentheses evaluates to false, jump to the command after the #end statement. If the condition evaluates to true, just continue normally.
  2. At the #end statement jump to the #while statement and start again.

That is:

  • When POV-Ray gets to the #while statement it evaluates the condition between parentheses.
  • If the statement evaluated to true then it will just continue normally with the next command.
  • However, if the statement evaluated to false, POV-Ray will skip the entire body of the loop and continue from the command after the #end statement.
  • At an #end statement POV-Ray will just jump back to the corresponding #while-statement and then continue normally (ie. testing the condition and so on).

Note that nowhere there is any mention about any index variable or anything else that could be used to automatically end the loop or whatever. As said, it is just a "dumb" loop that continues forever if necessary, only testing the statement between the parentheses (but it is not interested in what it is, only in its evaluated value).

Although one could easily think that this kind of "dumb" loop is bad and it should be more "intelligent" and better, the fact is that this kind of "dumb" loop is actually a lot more flexible and versatile. It allows you to make things not possible or very difficult to do with an "intelligent" for-loop with automatic index variables.

1.3.9.1 What a while-loop is and what it is not   1.3.9.3 How do I make a while-loop?


Copyright 2003-2004 Persistence of Vision Raytracer Pty. Ltd.