How to break out of two nested for loops?

Justin Sheehy justin at iago.org
Tue Jan 22 13:23:29 EST 2002


aahz at panix.com (Aahz Maruch) writes:

>>This solution keeps cropping up but, IMHO, using an *exception* for
>>something that isn't an exception is just as obscure, misleading and
>>awkward as a goto.
>
> That's an attitude.  It's an incorrect attitude, but it's one you share
> with a fair number of people.  You might want to check up on the
> workings of the for loop.

Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> writes:

> aahz at panix.com (Aahz Maruch) wrote:
>
>>That's an attitude.  It's an incorrect attitude, but it's one you share
>>with a fair number of people.  You might want to check up on the
>>workings of the for loop.
>
> You pompous fuckwit but thanks for your point of view.

You can call him names all you like, but he's right.

You should have paid attention to the last sentence of Aahz's post.

The for-loop construct in Python uses exceptions for termination.  Doing
so by hand is clearly in line with language idiom.

In Python, exceptions are often used as a general control flow
mechanism.  In some other languages, this may be awkward.  In Python,
it is a fairly standard idiom, and one followed by the language
implementation itself.

I personally also think that it tends to read very clearly and
smoothly when done properly, but that's the only part of this post
that is just my opinion.

-Justin

 





More information about the Python-list mailing list