Loops (was while true: !!!)

Blair Lowe Blair.Lowe at compeng.net
Wed Dec 27 21:14:26 CET 2000


At 16:56 +0000 2000/12/11, Jay O'Connor wrote:
>Here, you have both the the start, end, and step conditions. However, i is
>not immutable in the loop, so you could conceivably have something in the
>loop effect i, and therefor have an endless loop.

Daemons (Unix server programs such as the apache web server httpd) 
are examples of programs that should have an infinite loops. There 
are all over the place. The infinite loop construct is a standard 
construct as many here have said already. Limiting a loop just to 
make it a non infinite loop construct is not a solution unless there 
is a conditional reason to do so... thus the repeat ... until 
<condition> construct. Check out "UNIX Network Programming" by 
Stevens, published by Prentice Hall.

>I feel the approach of using "while (1):" could suffer the same 
>danger. Here you are literally declaring an endless loop, counting 
>on something to happen within the loop that will cause the loop to 
>end. If you have a bug or accident and that never happens, ooops....

That's why we debug.

There loops are often used to wait for signals, and have a routine in 
them that actually falls asleep so that little processor power is 
used in the meantime.

Debugging and testing should also be done on a development machine so 
that catastrophic errors do not occur that grind a production machine 
to a halt.

Computer Engineering Inc. http://www.compeng.net
Phone: 780 499 5687 (9 - 5 MST) Fax:   780 435 0693 (24 Hours)
All email advice that is provided for free is without warrantee: use 
at your own risk. 

More information about the Python-list mailing list