|
It depends on what you are trying to make.
The most common usage is to use it as a simple for-loop, that is, a loop which loops a certain number of times (for example 10 times) with an index value getting successive values (for example 1, 2, 3, ..., 10).
For this you need to first declare your index identifier with the first value. For example:
#declare Index = 1;
Now you want to loop 10 times. Remember how the condition worked: The while-loop loops as long as the condition is true. So it should loop as long as our 'Index' identifier is less or equal to 10:
#while(Index <= 10)
When the 'Index' gets the value 11 the loop ends, as it should.
Now we only have to add 1 to 'Index' at each loop, so we should do it at the end of the loop, thus getting:
#declare Index = 1; #while(Index <= 10) (some commands here) #declare Index = Index + 1; #end
The incrementation before the #end is important. If we don't do it, 'Index' would always have the value 1 and the loop would go forever since 1 is always less or equal to 10.
What happens here?
If you read carefully the above description you'll notice that the looping is done in a quite "dumb" way, that is, there's no higher logic hidden inside the loop structure. In fact, POV-Ray doesn't have the slightest idea how many times the loop is executed and what variable is used to count the loops. It just follows orders.
The higher logic in this type of loop is in the combination of commands we wrote. The effect of this combination is that the loop works like a simple for-loop in most programming languages (like BASIC, etc).
|