[Python-ideas] copyable iterators, named loops, continue a expression per indentation and a few functional things

Mathias Panzenböck grosser.meister.morti at gmx.net
Mon Dec 25 01:12:27 CET 2006

Eduardo "EdCrypt" O. Padoan schrieb:
>> Named loops
> This is an useful idea. But lets explore it a little.
> First, it is not exactly a name, a name is a reference to an object,
> it is more like a lable.
>> -----------
>> With named loops you could break or continue other than only the inner
>> most loop. I'm not sure about
>> a syntax, though.
> That is the useful part, and I will show why I think your syntax is
> not the best for it.
>> for x in X as loop_a:
> The 'as' keyword (not a keyword untill 2.6) is used to give a name to
> an object. Here, the lable 'loop_a', I think, should not be a name to
> any object.
> Second, it gives the impression that with '... X as loop_a' you are
> giving X the name 'loop_a'. It reads that way and it is how 'import
> ... as ...', 'with ... as ...' works and, in Py3k, how 'except ... as
> ...' will work. Your syntax is an exception to the 'OBJ as NAME'
> pattern, and could be misleading. The problem is, I couldnt think yet
> of any better syntax.
> Besides, the loop label is very usefull, and could be used in while
> too if someone find a better syntax.

Indeed, that's a problem. Also that a name should always be a object. Maybe:
break # breaks inner most loop
break . # the same
break .. # breaks parent
break ... # breaks grandparent

but this is ugly, too.

raise StopLoop(level)

I don't know.

Well this is a good way to break the outer most loop without any new syntax:

	while cond1():
		while cond2():
			if cond3():
				raise MyLoopStopper()
except MyLoopStopper:

But how to make something like this for continue?

More information about the Python-ideas mailing list