The rap against "while True:" loops

Mensanator mensanator at
Thu Oct 15 03:20:39 CEST 2009

On Oct 14, 12:07�pm, Ethan Furman <et... at> wrote:
> Mensanator wrote:
> > On Oct 14, 2:19 am, Dennis Lee Bieber <wlfr... at> wrote:
> >>On Tue, 13 Oct 2009 15:02:09 -0700 (PDT), Mensanator
> >><mensana... at> declaimed the following in
> >>gmane.comp.python.general:
> >>>You're not getting away that easy.
> >>>What's YOUR opinion of "whilr True"?
> >> Uhm... that it isn't valid in any language having English influence
> >>upon it's keywords...
> > Duh. You DO know that 'r' is next to 'e' on the
> > keyboard?
> Not on mine -- it's next to 'o' and 'u'. �:-) �Go Dvorak!

Does that mean you think "whilr" is a word?

> >> If anything -- I'd suggest a proposal to add a plain loop as a
> >>keyword in Python, whose effect is equivalent to a "while True", but a
> >>break must be used to exit said loop (well, we'll ignore raising an
> >>exception <G>)
> > And what will that accomplish? The problem isn't
> > using while True, it's the fact that you are
> > escaping the loop. Best Practice is to EXIT the
> > loop properly, not escape from it.
> I don't think anyone's arguing the opposite. �

I get the impression many people are, in fact,
arguing the opposite.

> What I *am* seeing argued
> is if it's the only correct way to do it, and that anyone who does it
> any other way is a scoundrel and a knave. �;-)

First of all, _I_ didn't bring up the concept of Best Practice,
nor have I insisted Best Practice means there is only one
correct way to do something. I interpret it as meaning there
may be many correct ways to do something, but of those,
this is the best way, barring special circumstances.

> For what it's worth, most of my loops run to completion, with no sign of
> a break anywhere. �Some have a break, and use it. �Some, even, (dare I
> say it?) use break *and* else! �

Breaks can be used properly, but it's easy to use them
improperly. How many of your loops start "while True"?

> And it's awesome! �Go Python! �:-D
> ~Ethan~

More information about the Python-list mailing list