The rap against "while True:" loops

Mensanator mensanator at aol.com
Tue Oct 13 18:02:09 EDT 2009


On Oct 12, 4:59�pm, David C Ullrich <ullr... at math.okstate.edu> wrote:
> kj wrote:
> > I'm coaching a group of biologists on basic Python scripting. �One
> > of my charges mentioned that he had come across the advice never
> > to use loops beginning with "while True". �Of course, that's one
> > way to start an infinite loop,
>
> Heh-heh: When I read this it occurred to me that another way to
> start an infinite loop would be to make a post here on this topic.
> Looking at the thread so far it appears I was right.

You're not getting away that easy.

What's YOUR opinion of "whilr True"?

>
>
>
> > but this seems hardly a sufficient
> > reason to avoid the construct altogether, as long as one includes
> > an exit that is always reached. �(Actually, come to think of it,
> > there are many situations in which a bona fide infinite loops
> > (typically within a try: block) is the required construct, e.g.
> > when implementing an event loop.)
>
> > 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"?
>
> > TIA!
>
> > kynn




More information about the Python-list mailing list