while true: !!!

Carsten Geckeler nospam at no.spam
Mon Dec 18 07:36:27 EST 2000

On Mon, 18 Dec 2000, Steve Lamb wrote:

> On Mon, 18 Dec 2000 01:19:51 -0700, Blair Lowe <Blair.Lowe at compeng.net> wrote:
> >This is exactly what a python program should be NOT doing. "while 1" 
> >is one of the most cryptic statements in Computer Science. 
>     Really?  I think it is actually one of the most obvious.  Esp. when one
> takes into consideration that you generally learn it once while learning how
> different people define their own way of doing an endless loop is a once per
> program experience.

Well, first of all, you have to understand that any value other than 0
evals to a true expression.  Then, of course, it's clear that `while 1:'
means a endless loop.  Anyway it's a very common idiom.  But the point is
that using true and false would make the code more readable in cases where
it's not clear, that the value is used as a boolean value later.  E.g:

# some code
exit = 0
# more code
if something:
	exit = 1
# more code
if exit:

I'd accept, that the variable exit itself helps to understand that it may
be uses as true or false, but it's no always that clear.

Cheers, Carsten
Carsten Geckeler:  carsten dot geckeler at gmx dot de
To get proper email-address replace `dot' and `at' by the corresponding symbols.

More information about the Python-list mailing list