4 ms·
I agree. I use it, but intuitively, I think of else acting the opposite way - if the loop finishes successfully, great! else, do something.
by thatswrong0 12y ago
I agree. I use it, but intuitively, I think of else acting the opposite way - if the loop finishes successfully, great! else, do something.
- eurleif 12y agoIf you're using break to signal success, that is how else acts.
- thatswrong0 12y agoI've been using break to signal failure. I'll keep that in mind.
- maxerickson 12y agoJust to illustrate: >>> for item in (1,2): print(item) else: print('Done!') 1 2 Done! >>> for item in (1,2): print(item) break else: print('Done!') 1 >>> edit: also: >>> for item in (): print(item) else: print('Done') Done
- deleted 12y ago[deleted]