Named code blockes

Alex Martelli aleaxit at yahoo.com
Sat Apr 14 08:53:59 EDT 2001


"Miki Tebeka" <tebeka at lycosmail.com> wrote in message
news:9b95ib$sq at news.or.intel.com...
> Hello All,
>
> Obviously I wasn't clear. :-(
>
> The problem I want to address is that continue and break always refer to
the
> innermost loop they're in. However, it may be desirable to name the loop
and
> then continue/break explictly this loop. (A know bug is that sometime a
new

Yes.  Java does that, as did, if I recall correctly, old PL/I.  I agree with
you
that it's a good feature to have (although calling it "named code blocks"
may be incorrect, and your specific example is pretty mysterious to me --
the purpose of the outer 'while1' escapes me).  Actually, named-continue
I see as definitely dispensable, but named-break would be useful.

In Python, you can code around this problem in various ways (besides
the classic ideas based on using state-flags to let the inner loop tell the
outer one it must terminate).  try/except is a very powerful building
block for all sorts of "get out of this nested construct" call, for example;
it also works across function calls, even recursive ones (its very power
and generality can make it less immediately clear than a more local
named-break would be, of course).


Alex






More information about the Python-list mailing list