[Python-ideas] Control Flow - Never Executed Loop Body

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Mar 23 19:27:11 EDT 2016


On 20/03/2016 18:12, Sven R. Kunze wrote:
> Hi Python-ideas,
>
> this is a follow up from an thread of Python-List:
> https://mail.python.org/pipermail/python-list/2016-March/705205.html
>
> What do you think about the following proposal?
>
> *Abstract*
> Control structures such as "for", "while" and "try" feature some various
> additional clauses being executed under certain conditions. This
> proposal adds another extra clause to "for" and "while" in order to
> provide an easy way to discover whether the body of a loop as never been
> executed at all.
>
> *Motivation**
> *Coming from the Web application development, we periodically can see a
> benefit of a hypothetical "empty" clause of Python's for loop like this:

I don't do hypothetical.  Practicality beats purity.

So having followed this thread I do not believe that language changes 
are needed.  So why not add a paragraph to this
https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops 
giving the cleanest solution from this thread for the way to write this 
Pythonically.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Python-ideas mailing list