I love Python's for-else feature. I've used it on a number of occasions, and have found it to be useful and to cut down on code.
However, I agree that the use of "else" is horribly confusing. When I teach "for-else" to students in my Python courses, they are often surprised by the functionality, and doubly surprised that the word "else" is used. I often joke that it would be a great feature, if only they had chosen something a bit more intuitive and memorable instead of "else", such as "if_we_exited_the_block_without_encountering_a_break". Slightly more seriously: While I realize that adding a keyword to Python isn't in the cards, a word such as "nobreak" would be easier for people to understand, and would stress the point of the functionality.
The fact that Emacs always tries to indent the "else" of a "for-else" to align with an "if" inside of the loop, rather than the "for" with which it matches, speaks volumes. I mean, if Emacs is confused, then how are we mere mortals supposed to remember?
So when I use "for-else", it's almost always in code that I am writing for myself, and that I don't expect others to read or maintain.
Don't forget that there's also "while-else", although I can't remember the last time I saw that actually used.
Agree with everything here! As a Python novice I found the name terrible, but nowadays I make use of it pretty frequently, and like the power which comes with it. I also use `try-except-else` (though I appreciate the "else" here has completely different semantics, I think it's something few people know about)
Emacs is really not a reference in terms of code indentation. I expect classic IDE to be much more robust at it, since emacs uses regex most of the time to determine indentation (the javascript mode is the only exception I remember), whereas I imagine a full-blown python IDE will actually parse the code.
However, I agree that the use of "else" is horribly confusing. When I teach "for-else" to students in my Python courses, they are often surprised by the functionality, and doubly surprised that the word "else" is used. I often joke that it would be a great feature, if only they had chosen something a bit more intuitive and memorable instead of "else", such as "if_we_exited_the_block_without_encountering_a_break". Slightly more seriously: While I realize that adding a keyword to Python isn't in the cards, a word such as "nobreak" would be easier for people to understand, and would stress the point of the functionality.
The fact that Emacs always tries to indent the "else" of a "for-else" to align with an "if" inside of the loop, rather than the "for" with which it matches, speaks volumes. I mean, if Emacs is confused, then how are we mere mortals supposed to remember?
So when I use "for-else", it's almost always in code that I am writing for myself, and that I don't expect others to read or maintain.
Don't forget that there's also "while-else", although I can't remember the last time I saw that actually used.