Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49105
| Date | 2013-06-24 18:13 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Is this PEP-able? fwhile |
| References | <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> <CAPTjJmrwNyF2-J8F3ii8W4WpkrNC67+i88ODLyiqHGa_7bz0Xg@mail.gmail.com> <20130624173050.5e16debf@bigbox.christie.dr> <CAA=1kxRp6o4OX3ES70j+O0xrSPfyyoZsU5x-qvNegCaY3QBYaw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3786.1372115499.3114.python-list@python.org> (permalink) |
On 2013-06-24 23:39, Fábio Santos wrote:
> On 24 Jun 2013 23:35, "Tim Chase" wrote:
> > On 2013-06-25 07:38, Chris Angelico wrote:
> > > Python has no issues with breaking out of loops, and even has
> > > syntax specifically to complement it (the 'else:' clause). Use
> > > break/continue when appropriate.
> >
> > from minor_gripes import breaking_out_of_nested_loops_to_top_level
>
> for x, y in itertools.product(range(width), range(height)):
This works nicely for certain use cases, but if there's additional
processing that needs to be done in the outer loops, it starts to get
hairy. As Ian Kelly mentions, I could really dig a labeled
break/continue in Python (it's one of the few ideas I like that Java
made pretty popular; though I can't say I particularly care for
Java's implementation). I'd love to see something like a decorator
where you could do things like the following pseudocode:
@toplevel
for i in range(height):
for j in range(width):
for component in data[i,j]:
if condition:
continue toplevel
elif other_condition:
break toplevel
else:
other processing
I'm not sure such a feature would ever arrive, but it would make it
easier than the current recommendation which is usually to either (1)
make inner loops into functions from which you can return; or (2)
raise a custom exception and then catch it in the outer loop.
-tkc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is this PEP-able? fwhile Tim Chase <python.list@tim.thechases.com> - 2013-06-24 18:13 -0500
csiph-web