Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Zachary Ware Newsgroups: comp.lang.python Subject: Re: for / while else doesn't make sense Date: Fri, 20 May 2016 10:59:59 -0500 Lines: 30 Sender: zachary.ware@gmail.com Message-ID: References: <573EC62F.4090401@lucidity.plus.com> Reply-To: python-list@python.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de PZDao3+9dkj9yhuxIHAySgM9+r3XYNhk2U7iu07Rmfhg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'anyway.': 0.04; 'context': 0.05; 'trailing': 0.07; 'optional': 0.09; 'subject:while': 0.09; 'python': 0.10; 'syntax': 0.13; 'suggest': 0.15; '2016': 0.16; 'erik': 0.16; 'gregory': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; 'sender:addr:gmail.com': 0.18; 'refers': 0.18; 'to:name:python- list@python.org': 0.20; 'am,': 0.23; 'slightly': 0.23; 'header:In- Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:google.com': 0.35; 'desirable': 0.35; 'item': 0.35; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'version': 0.38; 'received:209': 0.38; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'back': 0.62; 'subject: / ': 0.63; 'benefit': 0.66; '20,': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'special': 0.73; 'reply-to:addr:python.org': 0.84; 'subject:else': 0.84; 'subject:sense': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:from:date :message-id:subject:to; bh=G0JHMIz9ShR8QG0aGQqqUMAuFKh++DycxWLJkhhFyvc=; b=fh01yKX4pXsMaZ6lOvoVLcY3nNDwMk9nICngJX44cL5HVui7S8Z+Y8B/qovJdyzGwg zXhPaVls930VCtF+6bI23jj3ZmBvODu9VbXm6NljQW4i9AT/SEpgI7Rc6PvPz4PgGI1P 61QPd8fwOMsnJLciSoOtAal4qyaKA0UgEqDjhAeaYH9GHMVHiS6ce49HjZSmxUNTwIU9 lCUyh24w00p5zQrPdns/CBczX22TNURTm3tovcDmxJ/yENbzTM0k/i6I36xfKZqiieMv y1cvnHzNfXENSzrLCGKDz08+GHDtg1a5FnAS8PsTE4A5Yhmg3sDCBeIiChlWK0kJlSLr 8m4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:sender:in-reply-to :references:from:date:message-id:subject:to; bh=G0JHMIz9ShR8QG0aGQqqUMAuFKh++DycxWLJkhhFyvc=; b=TEmrODTsFJbylS19wUTIMnoQ/rvnPrmYY9u9JZwnbUoAcA3IIxZjdhNR0CuhTGdyhV MfoHHDs0EGALqEab1OfV+AvAPIyqCrmc/lRg0CHsNBng34akGJn7gB9uIy1wucv8PgBo pIRBRjvI5zQa2tYZo9Xt4k9ic6NIuBG5zsqXU7e6cyZkQgYJHY8x4VZBGePRsCuSSv57 bWoMUWEMHUdkRsByTXFv6UcMkzDbGDcJotYbaNtE4wT8n5H2K9/bV6G9KcdxBcE/3RjP VrTXzZ3shj5HvtXfR2vGBEyq4rT2W5dyO78NcaslUHC/PkpwicEcSn7x6xhP3eLZ+iFN ApGw== X-Gm-Message-State: AOPr4FVBD35eh3naL2Fr1BMlY1C7oI0y2c8HZgKy0HQCtmG9Mwejr01brq+ihyy2D5Mf50CMsOkFZf1I0aEDqw== X-Received: by 10.176.69.248 with SMTP id u111mr2242403uau.138.1463760019543; Fri, 20 May 2016 09:00:19 -0700 (PDT) In-Reply-To: <573EC62F.4090401@lucidity.plus.com> X-Google-Sender-Auth: ALtyXVId7XFTgU2WPp3adZeC8zY 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: <573EC62F.4090401@lucidity.plus.com> Xref: csiph.com comp.lang.python:108864 On Fri, May 20, 2016 at 3:09 AM, Erik wrote: > On 20/05/16 00:51, Gregory Ewing wrote: >> >> It's not so bad with "else" because you need to look back >> to find out what condition the "else" refers to anyway. > > > With my tongue only slightly in my cheek, if it was desirable to > "fix"/clarify this syntax then I would suggest adding some optional > (existing) trailing keywords to 'else' in this context that spells it out: > > for item in seq: > if foo(item): > break > else if not break: > nomatch() With tongue firmly cheeked, you can always use the special `:#` operator: for item in seq: if foo(item): break else:# if no break: nomatch() This has the benefit that you can use whatever syntax you like after the `:#`, and use it in any version of Python you want. -- Zach