[Python-Dev] PEP 315 - do while
Hans Polak
Hans.Polak at capgemini.com
Mon Oct 2 13:36:52 CEST 2006
Ok, I see your point. Really, I've read more about Python than worked with
it, so I'm out of my league here.
Can I combine your suggestion with mine and come up with the following:
do:
<setup code>
<loop body>
while <condition>
else:
<loop completion code>
Cheers,
Hans.
-----Original Message-----
From: Nick Coghlan [mailto:ncoghlan at gmail.com]
Sent: lunes, 02 de octubre de 2006 12:48
To: Hans Polak
Cc: python-dev at python.org
Subject: Re: [Python-Dev] PEP 315 - do while
Hans Polak wrote:
> Hi Nick,
>
> Yep, PEP 315. Sorry about that.
>
> Now, about your suggestion
> do:
> <setup code>
> while <condition>
> <loop body>
> else:
> <loop completion code>
>
> This is pythonic, but not logical. The 'do' will execute at least once, so
> the else clause is not needed, nor is the <loop completion code>. The
<loop
> body> should go before the while terminator.
This objection is based on a misunderstanding of what the else clause is for
in a Python loop. The else clause is only executed if the loop terminated
naturally (the exit condition became false) rather than being explicitly
terminated using a break statement.
This behaviour is most commonly useful when using a for loop to search
through
an iterable (breaking when the object is found, and using the else clause to
handle the 'not found' case), but it is also defined for while loops.
Regards,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
More information about the Python-Dev
mailing list