3 ms·
That's a very good point. I guess to me, I've already internalized the "else stands for when the loop doesn't terminate early ever" but for people new to the la
by noobermin 8y ago
That's a very good point. I guess to me, I've already internalized the "else stands for when the loop doesn't terminate early ever" but for people new to the language or feature it might be confusing. The fuzzy reasoning above was my original way of having it make sense in my head but I've since internalized the logic of how it really works.
- gh02t 8y agoYeah the thing I see that sometimes confuses people is that they think "else" works kinda like "finally" or "__exit__" in a context manager, where it's guaranteed to be called even if an exception is raised. I don't think there's anything wrong with thinking about it like you say, just need to be aware of a few edge cases. Else in a for loop is kinda obscure anyway, so its importance is marginal. It is really handy for a couple specific patterns, but I've only ever found myself using it a handful of times (and I write a lot of Python).