Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
bzb3
· 6y ago · 0 comments
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)
Comments
[–]
amitutk
6y ago
Yes, the else keyword is not intuitive. The best way to remember for/else is for/nobreak
[–]
neverartful
6y ago
Right! nobreak would make it much clearer.
[–]
Dagger2
6y ago
It would involve adding a new keyword to the language though. I imagine there was some desire to avoid that.
[–]
neverartful
6y ago
This was my guess too.