"for" with "else"?

Terry Reedy tjreedy at udel.edu
Thu Sep 25 19:34:48 EDT 2003


"Michael Geary" <Mike at DeleteThis.Geary.com> wrote in message
news:vn67fhhom95896 at corp.supernews.com...
> Mark Jackson wrote:
> > (This happens to be the *reverse* of what my intuition expects -
it
> > would seem more natural if the syntax meant "do this for loop to
> > completion, else do this extra stuff," but this is the way it is
and
> > one must simply remember it.)
>
> I'm with you there--the use of "else" here has seemed a bit
confusing to me.

How I plan to remember now: if the abnormal exit is a return or
exception, then all code end of for block, including any else part, to
the end of the function or try block will be skipped, so else part can
only apply to normal exit.

Terry J. Reedy






More information about the Python-list mailing list