Python scoping

Steve Horne sh at ttsoftware.co.uk
Mon Oct 30 06:03:05 EST 2000


On Fri, 27 Oct 2000 12:34:00 +0200, "Alex Martelli"
<aleaxit at yahoo.com> wrote:

>"Steve Horne" <sh at ttsoftware.co.uk> wrote in message
>news:gqeivsspqj64idsf6rr6dgbekif5t9osfo at 4ax.com...

>> Ada certainly allows some types of blocks to be named, and allows you
>> to use those names (for instance) to exit out of multiple layers of
>> loop in one go (sound like a hidden goto?)
>
>No, just a very useful and clear multi-level break.  Java has it
>too, as, I think I recall, does Perl (Perl's keyword for it being
>'last' rather than 'break').  In other languages, you have to fake
>this useful control structure with exceptions and try-blocks, or
>by wrapping the nested loops in a function that has no other reason
>to exist (return acts as the multi-level break).  I find explicit
>constructs for named-loop exit far preferable.

There are people who reguard break and continue to be hidden gotos. As
I never fully condemned gotos, I like to remind people when they are
using them.

As it happens, I prefer the ada version - the C, C++, Java, Python...
version tends to mean the break is hidden in a nested conditional
structure, and quite definitely obscures the structure of the code,
whereas the ada 'exit when' statement can clearly be indented at the
same level as the 'loop' and 'end loop' - making it a blatantly
obvious where ALL loop exits are.

Maybe an 'exit when' equivalent should be suggested to Guido?

-- 
Steve Horne
sh at ttsoftware.co.uk



More information about the Python-list mailing list