for -- else: what was the motivation?

rbowman bowman at montana.com
Sun Oct 9 02:45:31 EDT 2022


On 10/8/22 22:37, Axy wrote:
> Python is awesome because it's semantic is clear for the majority, but 
> there are places that look odd. In case of "for", "else" looks logically 
> tied with "for" clause, but actually it is not. It's tied with "break" 
> statement and I overlooked that even after re-reading the language 
> reference. If "else" was named like "never_broken_loop" or "nobreak", 
> the semantic would be perfectly clear. But, what's done is done.

It is sort of an overload for else. It does save an explicit test. For 
example, in C

for (i-0; i<length; i++)
{
     ....
}

if (i == length)
{
    what ever you though might happen didn't
}





More information about the Python-list mailing list