Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49105 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2013-06-24 18:13 -0500 |
| Last post | 2013-06-24 18:13 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Is this PEP-able? fwhile Tim Chase <python.list@tim.thechases.com> - 2013-06-24 18:13 -0500
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2013-06-24 18:13 -0500 |
| Subject | Re: Is this PEP-able? fwhile |
| Message-ID | <mailman.3786.1372115499.3114.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web