for / while else doesn't make sense
Steven D'Aprano
steve at pearwood.info
Fri May 20 23:50:15 EDT 2016
On Sat, 21 May 2016 10:24 am, Jon Ribbens wrote:
> On 2016-05-20, Ethan Furman <ethan at stoneleaf.us> wrote:
>> If you don't take the extra step of _break_ it is the usual case.
>
> Having an "for: else:" clause without a "break" would be so unusual
> that it's literally nonexistent, because it would always be a bug.
> So no, it isn't the usual case for "for: else:".
What do you mean? A for...else without a break is perfectly legal code, and
does *EXACTLY* what it is documented as doing:
- first the "for" block runs, looping as appropriate;
- THEN the "else" block runs, *once*.
How is this "always a bug"?
Would you classify the second line here:
print("Hello World!")
pass
as a bug? What exactly would your bug report be? "pass statement does
nothing, as expected. It should do nothing. Please fix."
>> But as others have said, this isn't going to change now, and I'm okay
>> with that. But, please, be a bit more understanding of those who don't
>> immediately grok the for/else and while/else loops.
>
> You're misunderstanding me. I'm not saying that the meaning of
> "for: else:" is 100% intuitively obvious.
I should hope not, because as it stands with the horribly misleading
keyword "else" it is counter-intuitive and confusing. Which is a crying
shame, because it is a useful feature that actually does make a lot of
sense, if only the keyword were better!
> I'm saying that it's
> *more* obvious than it would be if it used any of the other existing
> keywords. I suppose I'm also saying that there isn't any other
> obvious word that could be made into a keyword that would be better
> than "else" (even if we assumed that adding a new keyword was a
> cost-free exercise).
Well, that's a matter of opinion. And you know what they same about
opinions... there are always two, the foolish, pig-ignorant one, and mine.
:-)
--
Steven
More information about the Python-list
mailing list