<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>I agree there is no rap against "while True"-loops.  As an example these are very useful especially when receiving continuous data over a queue, pipe socket, or over any other connection.  You set to block, receive data, then process data and finally loop around to wait for next data segment.  Of course should protect against problems with try-except  wrappers and by handling exit conditions (e.g. "break") when appropriate.</DIV>
<DIV> </DIV>
<DIV>Is the problem with the specific syntax "while True:" or is it with having infinite loop constructs at all?</DIV>
<DIV><BR>--- On <B>Sat, 10/10/09, Stephen Hansen <I><apt.shansen@gmail.com></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="BORDER-LEFT: rgb(16,16,255) 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px"><BR>From: Stephen Hansen <apt.shansen@gmail.com><BR>Subject: Re: The rap against "while True:" loops<BR>To: python-list@python.org<BR>Date: Saturday, October 10, 2009, 8:30 PM<BR><BR>
<DIV id=yiv1212297331>
<DIV class=gmail_quote>
<BLOCKQUOTE style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>I use "while True"-loops often, and intend to continue doing this<BR>"while True", but I'm curious to know: how widespread is the<BR>injunction against such loops?</BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>The injunction is nonexistent (save perhaps in people coming from another language who insist that Python just /must/ have a "proper" do-while construct). "while True" with an exit-test at the end is idiomatic, how you spell "do-while" in Python. There's nothing at all wrong with it, and no real Python programmer will ever say don't-do-it.</DIV>
<DIV><BR></DIV>
<DIV>Okay, some people prefer to spell it 'while 1', but its the same difference.</DIV>
<DIV><BR></DIV>
<DIV>Yeah, you have to be certain the exit condition is there and properly formed so it can exit (unless you're using a generator which never empties, of course). But you have to make sure you have a proper exit condition on any looping construct anyways.</DIV>
<DIV> </DIV>
<DIV>No idea where your charge came across the advice, but its nonsense.</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<BLOCKQUOTE style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote> Has it reached the status of "best<BR>practice"?<BR></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Its simply the correct way to spell a do-while or intentionally infinite loop in Python, always has been.</DIV>
<DIV><BR></DIV>
<DIV>HTH,</DIV>
<DIV><BR></DIV>
<DIV>--S</DIV></DIV></DIV><BR>-----Inline Attachment Follows-----<BR><BR>
<DIV class=plainMail>-- <BR><A href="http://mail.python.org/mailman/listinfo/python-list" target=_blank>http://mail.python.org/mailman/listinfo/python-list</A><BR></DIV></BLOCKQUOTE></td></tr></table><br>