Re: Is this PEP-able? fwhile
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:
for i in range(height):
for j in range(width):
for component in data[i,j]:
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.
|All times are GMT. The time now is 11:36 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.