Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: for / while else doesn't make sense Date: Sat, 21 May 2016 14:01:52 +1000 Lines: 47 Message-ID: References: <573dfc0f$0$1586$c3e8da3$5496439d@news.astraweb.com> <573e54f7$0$1615$c3e8da3$5496439d@news.astraweb.com> <573FA496.5050708@stoneleaf.us> <573fdaf9$0$1584$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de mjbFc3NyER/3+kYWdr3m+A8Qds2elg3jHkyDlC+6pjbQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'cpython': 0.05; '21,': 0.07; 'bug.': 0.07; 'clause': 0.07; 'cc:addr:python-list': 0.09; 'expected.': 0.09; 'implies': 0.09; 'runs,': 0.09; 'subject:while': 0.09; 'bug': 0.10; 'python': 0.10; '"always': 0.16; '"break"': 0.16; '"for"': 0.16; '2016': 0.16; 'doing:': 0.16; 'false:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'looping': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:make': 0.16; 'true:': 0.16; 'world!")': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'documented': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'posted': 0.21; 'do.': 0.22; 'bug?': 0.22; 'pass': 0.22; 'am,': 0.23; 'code,': 0.23; 'code.': 0.23; 'sat,': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'message-id:@mail.gmail.com': 0.27; 'code:': 0.29; 'there.': 0.30; 'code': 0.30; 'statement': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'gets': 0.35; 'received:google.com': 0.35; 'nothing.': 0.35; 'something': 0.35; 'received:74.125.82': 0.35; "isn't": 0.35; 'step': 0.36; 'but': 0.36; 'should': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'no,': 0.38; 'does': 0.39; 'your': 0.60; 'subject: / ': 0.63; 'here:': 0.63; 'legal': 0.66; 'unusual': 0.72; 'chrisa': 0.84; 'subject:else': 0.84; 'subject:sense': 0.84; 'to:none': 0.91; 'ethan': 0.91; 'furman': 0.91 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:cc; bh=6Rlh7tCTPiheYDdMAE6b9Fd5t8wYHPt3X1XsrcPgXMU=; b=VAhv6dxyQ/FsXfi4NDvRC8jvPF3+y58d7kGEb0Aj1lIygrQBJXrRRhcv0/GC7WqzIa vHjFwe6atxZvpaE9yBzC8paf2b4jpr4wNlBWNnNMwmQxYvQ4JZeAsMoBmsX9ncXsVpMH qPydu7Ygh+2+9wahUK8tEqSjiQacqWXsJs5cxdrGNK8TPFN/k9q3K9B1uQDE8a6s6x17 ND+NOs4tUcgnqL6IKatoZ2x822UnNd4PQ8DUN0WnhKoxv7pyWYAgK9sufL1JkGwLnBI7 s1Ww3elIDYH8FtQ+9371/vWnccwmmuStM/IwKqxyVDDU1osxcXC5Aen/7Qiq7wAVR+MF usSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=6Rlh7tCTPiheYDdMAE6b9Fd5t8wYHPt3X1XsrcPgXMU=; b=clPjn0RgIjcFDQIsRkMtN1oSWjelKaYILA79uXW4GebbnvymlixuLxC38tM10pPDS+ vZ049rots9JGW/sblfBh6dh4ts7/wubKWldPt1bBX7JU2VrDiBgL9TuAavjGx23eSbie aqHrclci+h1YHHqPJKDodJyYYemzxI9D6QK2Tg7Y/Qo77hr/grFgMoLFY6D3Favc8MFK MSUjUyKfOKNe+lUkVpy4fjpmrVNE3FUvMtbcy4Sk1o27VfRoTObow3d56iDw5kJ6WPbe e3xR4RfXyBVoRPWD9KM0jozfMwTDeZ10gveKN1Qee0Tv0PpCfVT9vdE1KWvovZbhrYvI fn0g== X-Gm-Message-State: AOPr4FUtAbEwyW8XLKZYfXlSejPDfQFBqeaXwyloFqHaAiA3HxY97TIakVJDgwYassn5m2U4Bz6Ny8e0Uk8tLw== X-Received: by 10.194.186.237 with SMTP id fn13mr6591535wjc.47.1463803312461; Fri, 20 May 2016 21:01:52 -0700 (PDT) In-Reply-To: <573fdaf9$0$1584$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <573dfc0f$0$1586$c3e8da3$5496439d@news.astraweb.com> <573e54f7$0$1615$c3e8da3$5496439d@news.astraweb.com> <573FA496.5050708@stoneleaf.us> <573fdaf9$0$1584$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:108892 On Sat, May 21, 2016 at 1:50 PM, Steven D'Aprano wrote: > On Sat, 21 May 2016 10:24 am, Jon Ribbens wrote: > >> On 2016-05-20, Ethan Furman wrote: > >>> If you don't take the extra step of _break_ it is the usual case. >> >> Having an "for: else:" clause without a "break" would be so unusual >> that it's literally nonexistent, because it would always be a bug. >> So no, it isn't the usual case for "for: else:". > > > What do you mean? A for...else without a break is perfectly legal code, and > does *EXACTLY* what it is documented as doing: > > - first the "for" block runs, looping as appropriate; > - THEN the "else" block runs, *once*. > > How is this "always a bug"? > > Would you classify the second line here: > > print("Hello World!") > pass > > > as a bug? What exactly would your bug report be? "pass statement does > nothing, as expected. It should do nothing. Please fix." > Yes, I would. It's not a bug in Python or CPython - it's a bug in the second line of code there. It implies something that isn't the case. It's like having this code: if True: pass elif False: pass else: assert True It's well-defined code. You know exactly what Python should do. But is it good code, or is it the sort of thing that gets posted here: http://thedailywtf.com/articles/a-spiritual-journey ChrisA