On 25 July 2017 at 02:23, Ben Hoyt <benh...@gmail.com> wrote: > This is more of a python-ideas discussion, and Steven's answer is good. > > I'll just add one thing. Maybe it's obvious to others, but I've liked > for...else since I found a kind of mnemonic to help me remember when the > "else" part happens: I think of it not as "for ... else" but as "break ... > else" -- saying it this way makes it clear to me that the break goes with > the else. "If this condition inside the loop is true, break. ... *else* if > we didn't break, do this other thing after the loop."
For folks looking for a more in-depth explanation of the "if-break-else" approach to thinking about this construct: http://python-notes.curiousefficiency.org/en/latest/python_concepts/break_else.html That article also has a note explaining that we're unlikely to ever change this: http://python-notes.curiousefficiency.org/en/latest/python_concepts/break_else.html#but-couldn-t-python-be-different Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com