Breaking out of nested loops

Michael Kelly mkelly2002NOSPAM at earthlink.net
Sun Jan 13 15:53:24 EST 2002


On Sun, 13 Jan 2002 17:49:04 +0900, Jonathan Gardner
<jgardn at alumni.washington.edu> wrote:

>It was very easy to understand for me, and I think it made the code a lot 
>easier to write and think about. I've used it several times. I think the 
>other solutions (flags or exceptions) are a bit too cryptic.

A non-cryptic idiom in Perl!  I'll have to mark it down for posterity!
:)

I get a kick out of the "goto must die" mentality sometimes.
Surely just jumping all around in code makes it into a pile
of spaghetti and I'm aware of the "flushing the pipeline"
issues etc.. but if used sparingly a "goto" can be cleaner
esp. when coming out of nested loops.  You might have
some nested loops nested a little more than usual say
when you eliminate recursion by using another enclosing
loop.  Also the "flush the pipeline" arguments often only
take into consideration the source code look of the language
not realizing that many of these smooth-looking language
control structures devolve into a compare and jump when
disassembled anyway.  So a smart compiler may negate
the comparison to optimize when the jump is or isn't taken
depending on the processor architecture.

There's only so much you can do at the source code level
IOW. :)


Mike

--

"I don't want to belong to any club that would have me as a member."
    -- Groucho Marx



More information about the Python-list mailing list