[Python-ideas] Control Flow - Never Executed Loop Body
Sven R. Kunze
srkunze at mail.de
Thu Mar 24 13:44:51 EDT 2016
On 24.03.2016 14:54, Thomas Güttler wrote:
> for item in my_iterator:
> # do per item
> on empty:
> # this code gets executed if iterator was empty
> on break:
> # this code gets executed if the iteration was left by a "break"
> on notempty:
> # ...
>
Hmm, interesting. "on" would indeed be a distinguishing keyword to
"except". So, "except" handles exceptions and "on" handles internal
control flow (the iter protocol). Nice idea actually.
> }}}
>
> Is there a case which I have forgotten?
"on notbreak" I suppose.
I think the downside here is that we would need to register another
keyword "on". Is this used as a normal variable often?
Not sure if "on empty" can be registered as a single keyword since it
contains whitespace.
Best,
Sven
More information about the Python-ideas
mailing list