[Python-Dev] why not "return StopIteration"?

Barry A. Warsaw barry@digicool.com
Fri, 22 Jun 2001 12:30:44 -0400

>>>>> "GvR" == Guido van Rossum <guido@digicool.com> writes:

    |       - Calling an end() function would require two calls per
    |         iteration.  Two calls is much more expensive than one call
    |         plus a test for an exception.  Especially the time-critical
    |         for loop can test very cheaply for an exception.

Plus, if the exception is both raised and caught in C, it is never
instantiated, so exception matching is a pointer compare.  I know this
isn't the case with user defined iterators (since Python's raise
semantics is to instantiate the exception), but it helps.