3 ms·
Every time I go to use for...else, I need to look up what the behavior is, I can never remember if it's hitting the break or not hitting the break. That being s
by ehsankia 8y ago
Every time I go to use for...else, I need to look up what the behavior is, I can never remember if it's hitting the break or not hitting the break. That being said, python always tries to minimize the number of keywords, so re-using else makes more sense then introducing a whole new keyword for a niche usecase.
- fjsolwmv 8y ago...and then you realize that's why you shouldn't use it, right?
- fyi1183 8y agoThe way I remember it is that it makes sense in loops that search for something in an iterable. Such loops break when they're successful, and so it makes sense for the code in the else clause to run when the loop was unsuccessful.