5 ms·
[Mistake, a moderator please delete this comment! Completely agree with the parent comment now. for...else is dumb and unintuitive. I misunderstood its function
by vortico 8y ago
[Mistake, a moderator please delete this comment! Completely agree with the parent comment now. for...else is dumb and unintuitive. I misunderstood its function, which proves the above point to me.]
- Izkata 8y ago> The symantics of for...else are immediately obvious The code in your example is how it reads, but that's not how it works. The "obvious" reading is wrong, so it's obviously not "immediately obvious". This is what it's actually doing: found = False for l in get_list(): if ...: found = True break if not found: ...
- reificator 8y agoI think it's worth keeping the comment around for that exact reason. It underscores that the concept really is confusing and mislabeled.