Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'broken': 0.03; 'essentially': 0.04; 'guido': 0.05; 'plenty': 0.07; '"if': 0.09; '"break"': 0.16; 'broken:': 0.16; 'fond': 0.16; 'obviously,': 0.16; 'wrote:': 0.16; 'expanded': 0.18; 'email addr:gmail.com>': 0.20; 'trying': 0.22; 'of.': 0.22; 'code,': 0.23; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; 'equivalent': 0.27; 'expanding': 0.27; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.28; 'this.': 0.28; "i'm": 0.29; 'currently,': 0.29; 'that.': 0.30; 'url:mailman': 0.31; 'code': 0.31; "can't": 0.32; 'gets': 0.32; 'url:python': 0.33; 'done,': 0.33; 'skip:& 20': 0.34; 'skip:& 10': 0.34; 'received:google.com': 0.34; 'url:listinfo': 0.35; 'to:addr:python-list': 0.35; 'false': 0.35; 'really': 0.35; 'but': 0.36; 'url:org': 0.36; 'there': 0.36; 'two': 0.37; 'hi,': 0.37; 'should': 0.37; 'subject:: ': 0.37; 'front': 0.38; 'tue,': 0.38; 'someone': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'called': 0.40; 'skip:u 10': 0.62; 'places': 0.64; 'of:': 0.66; 'demand': 0.79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=fdu3/7wTAgmNcvOWgS8lS6xrKkCNDbn1vL7AfqeoorQ=; b=cZEqEJUqza3jBZt9mbbZlp+Ewjt3lR8ikBS8/mESpDTbufRkXXmVzoqee2905xrppv kCPpTWWJT9xtHk1yJQaoA7oGUL7EQ5JMc959iUP5jXoKwByF5N7XLWm616o66EPtv0Ag AnMNFlFCIyJYhwMw/HZxZF56sXjZ/CTq96CS6UaldPECfLpswdSHl/mP7h0i8haMrk4Q RIXb15C78a3dm+1pppLzPW6z2RMIIvnbtloKHXbaobRTZCOcsm8Zn+empiQG1/KyJS3R zEuZprERLQ0XO+aF8yMHC/X6P2FU0oaT4Ll/vVQdUBin0ncx1ycGKbN4soYTeR2kgdn1 9ZQA== X-Received: by 10.180.99.166 with SMTP id er6mr30378717wib.58.1433245771133; Tue, 02 Jun 2015 04:49:31 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Todd Date: Tue, 2 Jun 2015 13:49:09 +0200 Subject: Re: for...else To: python-list@python.org Content-Type: multipart/alternative; boundary=f46d04428ef610776505178789f0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 126 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433245778 news.xs4all.nl 2949 [2001:888:2000:d::a6]:42948 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91824 --f46d04428ef610776505178789f0 Content-Type: text/plain; charset=UTF-8 I think there is essentially zero chance of that. My understanding is that Guido regrets having "else" to begin with. But this should work broken = True for x in it: if complicated_calculation_1(): break complicated_calculation_2() if complicated_calculation_3(): break else: broken = False if broken: cleanup() On Tue, Jun 2, 2015 at 1:26 PM, acdr wrote: > Hi, > > Currently, in various places in my code, I have the equivalent of: > > for x in it: > if complicated_calculation_1(): > cleanup() > break > complicated_calculation_2() > if complicated_calculation_3(): > cleanup() > break > > Obviously, I'm repeating myself by having two separate calls to > cleanup(). I can't really see a nicer way to do this. (Though I see > plenty of non-nice ways to do this, such as adding "broken = True" in > front of every "break", and then after the loop is done, have an "if > broken" section.) Other solutions that I'm not particularly fond of > can be found on stackexchange, where someone else is trying to do the > same thing: > http://stackoverflow.com/questions/3296044/opposite-of-python-for-else > > I'm wondering if there is a demand for expanding the "for...else" > functionality to be expanded also have a block of code that only gets > called if the loop is broken out of. I.e.: > > for x in it: > ... > then: > # "break" was called > ... > else: > # "break was not called > ... > -- > https://mail.python.org/mailman/listinfo/python-list > --f46d04428ef610776505178789f0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I think there is essentially zero chance of that.=C2= =A0 My understanding is that Guido regrets having "else" to begin= with.

But this should work

broken =3D = True
for x in it:
=C2=A0 =C2=A0 if complicated_calculation_1():
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 break
=C2=A0 =C2=A0 complicated_calculation_2()
=C2=A0 =C2=A0 if complicated_calculation_3():
=C2=A0 =C2=A0 =C2=A0 =C2=A0 break
else:
=C2=A0= =C2=A0=C2=A0 broken =3D False
if broken:
=C2=A0= =C2=A0=C2=A0 cleanup()


On Tue, Jun 2, 2015 at 1:26 PM, acdr <mail.acdr@gmail.com> wrote:
Hi,

Currently, in various places in my code, I have the equivalent of:

for x in it:
=C2=A0 =C2=A0 if complicated_calculation_1():
=C2=A0 =C2=A0 =C2=A0 =C2=A0 cleanup()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 break
=C2=A0 =C2=A0 complicated_calculation_2()
=C2=A0 =C2=A0 if complicated_calculation_3():
=C2=A0 =C2=A0 =C2=A0 =C2=A0 cleanup()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 break

Obviously, I'm repeating myself by having two separate calls to
cleanup(). I can't really see a nicer way to do this. (Though I see
plenty of non-nice ways to do this, such as adding "broken =3D True&qu= ot; in
front of every "break", and then after the loop is done, have an = "if
broken" section.) Other solutions that I'm not particularly fond o= f
can be found on stackexchange, where someone else is trying to do the
same thing:
http://stackoverflow.com/questions/3296044/opposi= te-of-python-for-else

I'm wondering if there is a demand for expanding the "for...else&q= uot;
functionality to be expanded also have a block of code that only gets
called if the loop is broken out of. I.e.:

for x in it:
=C2=A0 =C2=A0 ...
then:
=C2=A0 =C2=A0 # "break" was called
=C2=A0 =C2=A0 ...
else:
=C2=A0 =C2=A0 # "break was not called
=C2=A0 =C2=A0 ...
--
https://mail.python.org/mailman/listinfo/python-list

--f46d04428ef610776505178789f0--