News for hackers. Stuff that matters.
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)
Re:The for/Else Statement in Python by amitutk on Thursday July 09, 2020 @10:12AM (#23780436)
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.
Re:The for/Else Statement in Python by Dagger2 on Friday July 10, 2020 @01:20AM (#23788396)
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.