The rap against "while True:" loops

Raymond Hettinger python at rcn.com
Tue Oct 13 03:00:30 CEST 2009


[kj]
> I use "while True"-loops often, and intend to continue doing this
> "while True", but I'm curious to know: how widespread is the
> injunction against such loops?  Has it reached the status of "best
> practice"?

This is the first I've ever heard of such an quasi-injunction.
Like you, I use "while True" often.  We use it frequently
in the standard library and have no PEP 8 admonition
against it, nor does pychecker report it as a negative practice.
The use of "while 1" loops has a long history in other langauges
as well.

So, if you hear someone make-up a new "best practice" proscibing
"while True", just smile and continue to write programs as you
have been.  You will not be alone.  Many excellent programmers
write "while True" whenever it is called for.


Raymond



More information about the Python-list mailing list