POV-Ray : Newsgroups : povray.advanced-users : #while loop help Server Time
30 Jul 2024 04:17:42 EDT (-0400)
  #while loop help (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
From: Bob Hughes
Subject: Re: #while loop help
Date: 3 Sep 2000 16:42:57
Message: <39b2b7d1$1@news.povray.org>
"ingo" <ing### [at] homenl> wrote in message
news:8FA4E57A0seed7@204.213.191.228...
| python it indeed is all (more or less) automatic.
|
| while i in range(25):
|   while j in range(25):
|     do some things here inside the loops
|
| continue program outside the loop

That looks awfully easy.  Why the word "in" though?  Just so you don't think
it's too simple?

Bob


Post a reply to this message

From: Chris Huff
Subject: Re: #while loop help
Date: 3 Sep 2000 17:08:25
Message: <chrishuff-F3A9F1.16100403092000@news.povray.org>
In article <8FA4E57A0seed7@204.213.191.228>, ing### [at] homenl (ingo) 
wrote:

> Think about it with an absolute non-programmer mind.

Easier said than done.


> 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.

This is done for flexibility and ease of coding...a variable is just a 
variable, whether you use it as a counter or not, how is POV supposed to 
know it needs to be incremented when the loop ends? Also, there are 
times when you want to increment the loop by a different amount, and 
times when you don't even want to use an incrementing variable for 
control. Loops aren't only used for making several copies of an object.


> 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.

This could make sense if you created the variable inside the outer loop 
in many other languages, but if you create it outside both loops, why 
would you expect it to be destroyed when the outer one loops back to 
it's start?
Anyway, POV seems to only have variables local to files and macros. With 
a separate keyword for modifying variables, like what my #set patch 
implements, it would be possible to use variables local to any block, 
like #if statements and #while loops, but I don't expect that to happen 
for a while, if ever.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Warp
Subject: Re: #while loop help
Date: 4 Sep 2000 09:21:31
Message: <39b3a1da@news.povray.org>
Ok, I added an entry about the while loops and made a page about it:

http://iki.fi/warp/povVFAQ/whileloops.html

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 4 Sep 2000 11:17:28
Message: <8FA5ADEABseed7@204.213.191.228>
Bob Hughes wrote:

>That looks awfully easy.  

That why I like it.

>Why the word "in" though?  Just so you don't
>think it's too simple?

Don't ask me...


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 4 Sep 2000 11:20:07
Message: <8FA5B4D28seed7@204.213.191.228>
Warp wrote:

>  Ok, I added an entry about the while loops and made a page about it:
>
>http://iki.fi/warp/povVFAQ/whileloops.html
>

excellent!

Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 4 Sep 2000 11:29:12
Message: <8FA5BA95Bseed7@204.213.191.228>
Chris Huff wrote:

<snip>
>it would be possible to use variables local to any block, 
>like #if statements and #while loops, but I don't expect that to happen 
>for a while, if ever.

Neither do I, nor do I want it. It was just to illustrate how "illogic" a 
total non-programmer can think(me, two years ago, after only two days 
playing with POV). 
Compare it to chess. You can learn anybody the moves each piece can make, 
but he'll only be able to play chess after he grasps the concept behind 
the game.


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: Peter J  Holzer
Subject: Re: #while loop help
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

From: Warp
Subject: Re: #while loop help
Date: 5 Sep 2000 10:45:27
Message: <39b50707@news.povray.org>
I just added more stuff at the end of the document, if someone is interested.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Phil Clute
Subject: Re: #while loop help
Date: 5 Sep 2000 18:55:00
Message: <39B57A0C.D636AC0F@tiac.net>
Yours looks more in-depth but Sonya Roberts has a #while tutorial
at the Rendering Times...
http://www.spake.org/rtimes/article/povindx.htm
-- 
Phil
...coffee?...yes please! extra sugar,extra cream...Thank you.


Post a reply to this message

From: Ken
Subject: Re: #while loop help
Date: 5 Sep 2000 20:54:28
Message: <39B59562.7B9464E3@pacbell.net>
Phil Clute wrote:
> 
> Yours looks more in-depth but Sonya Roberts has a #while tutorial
> at the Rendering Times...
> http://www.spake.org/rtimes/article/povindx.htm

Were it not for that tutorial I never would have understood #while loops.

-- 
Ken Tyler - 1400+ POV-Ray, Graphics, 3D Rendering, and Raytracing Links:
http://home.pacbell.net/tylereng/index.html http://www.povray.org/links/


Post a reply to this message

<<< Previous 4 Messages Goto Initial 10 Messages

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