The rap against "while True:" loops

Ethan Furman ethan at stoneleaf.us
Wed Oct 14 13:07:38 EDT 2009


Mensanator wrote:
> On Oct 14, 2:19�am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> 
>>On Tue, 13 Oct 2009 15:02:09 -0700 (PDT), Mensanator
>><mensana... at aol.com> 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!

>>� � � � 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.  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.  ;-)

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!  And it's awesome!  Go Python!  :-D

~Ethan~



More information about the Python-list mailing list