Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.094 X-Spam-Evidence: '*H*': 0.81; '*S*': 0.00; 'iterate': 0.09; 'does,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'roy': 0.16; 'worse.': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'written': 0.21; 'earlier': 0.24; 'source': 0.25; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'correct': 0.29; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'accidentally': 0.31; 'bug?': 0.31; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'turn': 0.37; 'received:209': 0.37; 'starting': 0.37; 'expected': 0.38; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'simply': 0.61; "you're": 0.61; '30,': 0.65; 'smith': 0.68; 'results': 0.69; 'ending': 0.78; 'not:': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=zVMY9EXRxMzMy9FsDYZrBNUWFLowkC/hA2yP68V+Ix0=; b=VYrctdJ4oEtJM6Tm7rQUxDBffDAfokGo95TMb5tk+SUkhwyRiIhL7lk7KliZ8+v113 sF65E6iw7l5AP+IWT3/dRpgTjUM13l82aPfOZ4P+vl/BvGe4fDcH8VlRa428Ks2nf9P2 0rS5zbkXyi2FBBOINo66HGUiVQ2s9pesAmK/N1tqVNYQmvv0eqfUgehpG4KAedjp2+No 6Ej6uN5K7oZko7cAEXRBrhvD3lFnO/n2YSx3tSSw6lScTi8vBhPokxclG+npnl1v3gOX KEu2kdjn79L8VdSi7LRHyTSNARYL6kMVfzVFQ4Yv+UxsDAMoGGv+xQrz8B0JEQTpuXfw V2cQ== MIME-Version: 1.0 X-Received: by 10.52.155.67 with SMTP id vu3mr4517000vdb.94.1369918707572; Thu, 30 May 2013 05:58:27 -0700 (PDT) In-Reply-To: References: <5f101d70-e51f-4531-9153-c92ee2486fd9@googlegroups.com> <51a1fc7b$0$30002$c3e8da3$5496439d@news.astraweb.com> <2abf4e9c-8c3b-4e2f-80c9-50c1f1d75c9d@googlegroups.com> <51a4b5a1$0$29966$c3e8da3$5496439d@news.astraweb.com> <04b90c02-833a-4bad-88ad-ab71178b8f79@googlegroups.com> <51a6df59$0$11118$c3e8da3@news.astraweb.com> Date: Thu, 30 May 2013 22:58:27 +1000 Subject: Re: Short-circuit Logic From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369918710 news.xs4all.nl 15990 [2001:888:2000:d::a6]:57957 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46482 On Thu, May 30, 2013 at 10:40 PM, Roy Smith wrote: > if somebody were to accidentally drop three zeros into the source code: > >> x = 1000 >> while x < 173: >> print(x) >> x += 1 > > should the loop just quietly not execute (which is what it will do > here)? Will that make your program correct again, or will it simply > turn this into a difficult to find bug? If you're really worried about > that, why not: If you iterate from 1000 to 173, you get nowhere. This is the expected behaviour; this is what a C-style for loop would be written as, it's what range() does, it's the normal thing. Going from a particular starting point to a particular ending point that's earlier than the start results in no iterations. The alternative would be an infinite number of iterations, which is far far worse. ChrisA