Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Selik Newsgroups: comp.lang.python Subject: Re: for / while else doesn't make sense Date: Fri, 20 May 2016 15:26:59 +0000 Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de U8byRfQDAdG/W678OovvVANNwP8uGspjWOozXIxGNN4g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'executed': 0.07; 'repeated': 0.07; 'exiting': 0.09; 'logic': 0.09; 'loop.': 0.09; 'semantics': 0.09; 'subject:while': 0.09; 'utilizing': 0.09; 'python': 0.10; 'exception': 0.13; 'instead.': 0.15; 'thu,': 0.15; '"finally"': 0.16; '*always*': 0.16; '2016': 0.16; 'denotes': 0.16; 'executed.': 0.16; 'false),': 0.16; 'iteration,': 0.16; 'keyword.': 0.16; 'nick': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sense,': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; '>': 0.18; 'email addr:gmail.com>': 0.18; 'all,': 0.20; 'to:2**1': 0.21; 'implicit': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'sense': 0.26; 'handling': 0.27; 'not.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'block,': 0.29; 'certain': 0.31; 'post': 0.31; 'another': 0.32; 'good.': 0.32; 'point': 0.33; 'view,': 0.33; "i'll": 0.33; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'clear': 0.35; 'sometimes': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; '(i.e.': 0.36; 'keyword': 0.36; 'structures': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'received:209': 0.38; 'end': 0.39; 'test': 0.39; 'url:en': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'where': 0.40; 'ever': 0.60; 'skip:u 10': 0.61; 'further': 0.62; 'here.': 0.62; 'subject: / ': 0.63; 'great': 0.63; 'construct': 0.84; "it'd": 0.84; 'subject:else': 0.84; 'subject:sense': 0.84; 'to:name:python': 0.84; 'url:latest': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=y0IkVpmtQer9nY9q5Z1vyqTGuZ68QqKzjgtrCJiz1OM=; b=dlWvc9pICU3LuYqRrR9sQKfCACmRI9F4K1RVvm1dZHsgD0JbQeuSz7QxwWrZkUdxT6 GswzbYpGPbT49w9fNDGI0w7Y+6lumkFQR98TBIjbCeFO6QItFbddD5CTJ+sjZay7WVnn fOigxUeWU5J4rbxcz7glWOWNd3KWHrngjkiOxpdByJwe0lZp8A1wUdZM+igQ2oU274bn Sc+9QwUBd1gDX/wbOHtrvkYyFoDfkpKScHpRS5NH7SahxlA0esVqi7MiiHC9eJ8lRqh4 aTaAtlllTsiWSWH0PyZOleMcd8whSOz8DohhuhsPCYZbG3+HGNHkwwr5ws6wEHfdQNuA e/hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=y0IkVpmtQer9nY9q5Z1vyqTGuZ68QqKzjgtrCJiz1OM=; b=F/ksfmJHI2j+kKaIF+M7sIQK/QcnMHPvfLxTD+CJjqQM+WTkuzOC7OzV1mRm9aNfwp F5urGtkh31XqLLdy/WJQLKcVlcuaISvC42+zaLk5XeHNyIcA8nQR6wSZsqw2vjo5vUGZ Jk4Mnvot4jq9c4XFnXcP/ElKPYTKSDa8IuMjN0zc/ACshQ8Gd2bk4CxTsC9vB4eidFXJ rBSEorpBKqWT569+HYPcMDm/8G5Wc3QxlkasM+oSxnjySIxXapmHzue9P6Nez0AdMEo7 Gy7s0r72FrqhphUv9T0OY7m768+VCerGJ+uVYeql99dqj2DmLgAqQ7brjIuutPsJ1XG1 WuOQ== X-Gm-Message-State: AOPr4FVLCmcSthdFNl9oJE2KFiMUgftRmAPdOj/qYksAR8KE7qZJENLsT23vhMnzFh06j8DxFXL6DAKKEGm58w== X-Received: by 10.140.170.132 with SMTP id q126mr4034450qhq.103.1463758028743; Fri, 20 May 2016 08:27:08 -0700 (PDT) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.22 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: Xref: csiph.com comp.lang.python:108862 On Thu, May 19, 2016 at 1:04 PM Ian Kelly wrote: > On Thu, May 19, 2016 at 10:31 AM, Herkermer Sherwood > wrote: > > Most keywords in Python make linguistic sense, but using "else" in for > and > > while structures is kludgy and misleading. I am under the assumption that > > this was just utilizing an already existing keyword. Adding another like > > "andthen" would not be good. > > "else" makes sense from a certain point of view, but I think that > logic may not be communicated well. At the start of each loop > iteration, the loop construct makes a test for whether the loop should > continue or not. If that test ever fails (i.e. if the condition of the > while loop is false), the else block is executed instead. So you can > think of it as a repeated if-else where the else block has the > additional effect of exiting the loop. > > > But there is already a reserved keyword that would work great here. > > "finally". It is already a known keyword used in try blocks, but would > work > > perfectly here. Best of all, it would actually make sense. > > > > Unfortunately, it wouldn't follow the semantics of > try/except/else/finally. > > "finally" in exception handling denotes a block that is *always* > executed. Using it for a block that is only sometimes executed would > dilute that meaning. > It's unfortunate that so many people responded so quickly, since Ian's explanation was so clear (I thought). For further clarity, I'll write out the implicit if-statement that Ian described, though in my case it'd be at the end of the block, somewhat like a do-while: IF keep_looping() THEN GOTO LOOP_START ELSE GOTO LOOP_COMPLETED Also, Nick Coghlan has a good post about this ( http://python-notes.curiousefficiency.org/en/latest/python_concepts/break_else.html )