Re:The for/Else Statement in Python
by bzb3 on Thursday July 09, 2020 @09:40AM
(#23780042)
Surprising. I didn't know this construct and I would naturally assume that the else part would execute if the loop never spun (because the list/etc was empty)
[ Parent
| on HN ]
Yes, the else keyword is not intuitive. The best way to remember for/else is for/nobreak
Re:The for/Else Statement in Python
by neverartful on Thursday July 09, 2020 @11:21AM
(#23781222)
Right! nobreak would make it much clearer.
It would involve adding a new keyword to the language though. I imagine there was some desire to avoid that.
Re:The for/Else Statement in Python
by neverartful on Thursday July 09, 2020 @10:06AM
(#23780362)
This was my guess too.