[Python-ideas] Immemorial desire for "do-while"-like construction

Nick Coghlan ncoghlan at gmail.com
Thu Jul 16 13:49:19 CEST 2009

Steven D'Aprano wrote:
> On Thu, 16 Jul 2009 08:50:06 am Jan Kaliszewski wrote:
>> Hello,
>> The issue has been coming back repeatedly:
> And not very long ago at that.

So often that there's even a PEP* that documents the pros and cons of
different ideas and points out that a viable syntactic challenger to the
"while True with inner break" approach has yet to be found.

The current idiom does have the downside of potentially hiding the
termination condition, but it otherwise handles generalised looping very
nicely. (Putting the break on a separate line also helps a great deal
with the visibility of the termination condition)


* http://www.python.org/dev/peps/pep-0315/

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list