POV-Ray : Newsgroups : povray.advanced-users : #while loop help : Re: #while loop help Server Time
30 Jul 2024 06:25:40 EDT (-0400)
  Re: #while loop help  
From: Peter J  Holzer
Date: 4 Sep 2000 18:01:01
Message: <slrn8r847i.jut.hjp-usenet@teal.h.hjp.at>
On 3 Sep 2000 16:10:41 -0400, ingo wrote:
>Think about it with an absolute non-programmer mind.
>When I first encouterd a loop, it took men an hour to realize that I had 
>to do the incrementing myself. I expected it to be automatic.
>It took me a day to figure out I had to reset the counter of the inner 
>loop myself. For me it seemed very logical that once I had gone through 
>the loop the counter would not exist anymore until the loop was enterd 
>again.

In most languages this is the difference between a while loop and a for
loop. The while loop is repeated while a certain condition is true. The
for loop is repeated for a set of values. 

For example, in

#local a = 0;
#while (a < 20) 

    ...

#end

You can do everything with a inside the loop, as long as you stay below
20. You don't just have to increase it by 1 with every cycle. You can
increase it by 0.1, by a random value, you can decrease it again, or you
can compute it as a function of some other variable.

On the other hand, Pascal (for example) has a for loop:

var i: integer;

begin
    i := 5;

    for i := 1 to 20
    do
	println(i);
    done
    println(i);		{ ??? }
end;

will print the values from 1 to 20. No need to increment manually,
because the loop always increments the count by 1. In fact you are not
allowed to assign a new value to i inside the loop, and it isn't
specified what the println after the loop will print. 5, 20, or 21 would
be values you could expect (if you know a little bit about how a pascal
compiler works), but it could also be some completely random value.

So the for loop is simpler, but less flexible. Because you can always
rewrite a for loop as a while loop, but not vice versa, Povray only has
a while loop.

	hp

-- 
   _  | Peter J. Holzer    | Nicht an Tueren mangelt es,
|_|_) | Sysadmin WSR       | sondern an der Einrichtung (aka Content).
| |   | hjp### [at] wsracat      |    -- Ale### [at] univieacat
__/   | http://www.hjp.at/ |       zum Thema Portale in at.linux


Post a reply to this message

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