how about:

for something in some_iterable:
else if not break:

No new keywords :-)


for something in some_iterable:
else:  # if not break:

and no changes needed to Python!

I may actually start doing that myself ...

As for the "loop didn't run at all" case: Does anyone find a need for that? Personally, I've found that everytime I do some kind of check for an empty iterable before a loop, it was totally unnecessary.

A for loop means: "Do this stuff to all the items in this iterable."

Most of the time, if there's nothing there, you don't need to do the stuff, and that's that.


On Tue, Jul 21, 2020 at 5:28 PM Ethan Furman <> wrote:
On 7/20/20 7:34 AM, Barry Scott wrote:

> To avoid the ambiguity of `if` after `for` why not follow `for` with `elif`?
> for x in ...:
> ...
> elif break:
> # break was called
> elif not break:
> # looped at least once and break not used
> elif pass:
> # same as else today
> # loop'ed no times
> (I always have to think what else means after a for).

Keep thinking... ;)

`else` today /does not/ mean "loop'ed no times".  To copy Steven
D'Aprano's example:

>     py> for x in [1,2]:
>     ...     print("inside loop")
>     ... else:
>     ...     print("elif never looped")
>     ...
>     inside loop
>     inside loop
>     elif never looped

> Mistaking the semantics for "if never looped" is a very common mistake.
> Welcome to the club :-)

Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct:

Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython