Behavior of the for-else construct

Avi Gross avigross at verizon.net
Thu Mar 3 22:35:38 EST 2022


That is one way to look at it, Jach. Of course, a particular loop may have multiple break statements each meaning something else. The current implementation makes all of them jump to the same ELSE statement so in one sense, I consider the ELSE to be associated with the loop as a whole. Sometimes the loop may not even have a break statement and yet the dangling ELSE seems to be accepted anyway.

Some languages allow you to break out of deeply nested loops by jumping up two or more levels, perhaps to a label and are more of a goto. I shudder to think how that would work if each loop had an ELSE dangling. 


-----Original Message-----
From: Jach Feng <jfong at ms4.hinet.net>
To: python-list at python.org
Sent: Thu, Mar 3, 2022 9:22 pm
Subject: Re: Behavior of the for-else construct


I never feel confused by "else" because I always think it in "break...else", not "for...else". For those who always think in "for...else" deserves this confusion and it can't be just escaped by replacing with another magic word such as "then" or "finally" etc:-)



--Jach



-- 

https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list