Pythonically-expressed nested-loop break?

Steven Majewski sdm7g at Virginia.EDU
Mon Jan 14 16:17:45 EST 2002


On Mon, 14 Jan 2002, John Roth wrote:

> "Bengt Richter" <bokr at oz.net> wrote in message
>
> I used to think this was a good idea. Now that I'm
> getting into the Test First Design part of XP, I'm becoming
> a real believer in short and simple methods that can be
> tested easily, and nested loops are one of the harder
> to test constructs. If you break out the inner loop so it
> can be tested in isolation, the 'break' statement becomes
> completely irrelevant.

I agree, John: That's what I meant when I said that the real
problem with breaking out of a deeply nested loop may be a
program design problem, rather than a language design problem.

Some of the other syntax suggestions would be easier to write,
but I haven't seen one (except perhaps Bengt's colons) that
is any easier to read and understand than the nested try/except
solution. That is, except for breaking it into smaller routines,
which seems to beat ALL of the syntax suggestions.

 I'm not wild about Bengt's solution. If we were going to go that
far towards a visual representation, I'ld rather see lines and
arrows (which is what I'ld probably scrawl across the source code
printout so that I could see the flow better, anyway.) But until
we have non-character based visual programming editor & IDE for
Python, I think either magic colons or  lines --------
                                                     |
                                                    and
                                                     |
                                                     V
                                                   arrows

would make the problems some folks have now with mixed tabs and
spaces seem trivial in comparison!

-- Steve Majewski






More information about the Python-list mailing list