I (and others) think that "else" in this context should be replaced by
something more evocative, such as "ifnobreak".
I always have to think twice about this construct, and the way I grok it
is by mentally making this substitution.
Best wishes
Rob Cliffe
On 14/05/2026 18:16, Ethan Furman wrote:
On 5/14/26 01:32, Left Right via Python-list wrote:
> [...] "else" is
> allowed in "strange" places in Python, eg.
>
> for var in iterator:
> else:
> statement
>
> with the intention of executing the "statement" when the loop exits
> early.
Not sure what you mean by "exits early", but the `else` statement will
run unless `break`
is encountered in the `for` loop.
--
~Ethan~
--
https://mail.python.org/mailman3//lists/python-list.python.org