Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:while': 0.07; 'python': 0.08; 'loop.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; '"while': 0.16; '"with"': 0.16; 'habit.': 0.16; 'lines),': 0.16; 'wrote:': 0.16; '2.2': 0.18; "they've": 0.18; 'jan': 0.19; '(which': 0.19; 'literal': 0.23; 'string': 0.24; 'code': 0.25; 'suggestion': 0.25; '"the': 0.26; 'skip:p 30': 0.29; 'sun,': 0.30; "i've": 0.31; 'version': 0.31; 'received:24': 0.32; 'break': 0.32; 'list': 0.32; 'header:User- Agent:1': 0.33; 'to:addr:python-list': 0.33; 'loop': 0.34; 'too': 0.34; 'statement,': 0.34; 'typical': 0.34; 'header:X-Complaints- To:1': 0.34; 'received:org': 0.37; 'could': 0.37; 'steven': 0.38; 'mailing': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'believe': 0.65; 'lost': 0.68; 'soon': 0.71; 'idiom': 0.84; 'temperature': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dan Sommers Subject: Re: while True or while 1 Date: Sun, 22 Jan 2012 16:05:51 +0000 (UTC) References: <4F1AC1D4.2080402@gmail.com> <4f1b9dc4$0$29987$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 24.100.92.194 User-Agent: Pan/0.133 (House of Butterflies) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327248367 news.xs4all.nl 6861 [2001:888:2000:d::a6]:33561 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19217 On Sun, 22 Jan 2012 05:25:25 +0000, Steven D'Aprano wrote: > Or they've been writing Python code since before version 2.2 when True > and False were introduced, and so they are used to the "while 1" idiom > and never lost the habit. That would be me. As per a now-ancient suggestion on this mailing list (I believe it was by Tim Peters), I've also been known to use a non-empty, literal Python string as a self-documenting, forever-True value in the typical loop-and-a- half cnstruct: while "the temperature is too big": temperature = get_temperature() if temperature <= threshold: break process_temperature(temperature) This way, even though the loop condition is buried inside the loop (which could be longer than four lines), it is apparent as soon as I encounter the loop. With the advent of the "with" statement, though, these loops are slowly disappearing. -- Dan