468,304 Members | 1,433 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,304 developers. It's quick & easy.

Re: PEP on breaking outer loops with StopIteration


Quoting Kris Kowal <kr********@cixar.com>:
I had a thought that might be pepworthy. Might we be able to break
outer loops using an iter-instance specific StopIteration type?

This is the desired, if not desirable, syntax::

import string
letters = iter(string.lowercase)
for letter in letters:
for number in range(10):
print letter, number
if letter == 'a' and number == 5:
raise StopIteration()
if letter == 'b' and number == 5:
raise letters.StopIteration()
I must say, I don't even like the idea of having a 'break', but I kind oflike
this proposal.

However, it may be ambiguous [is that a word?] if the outer and inner forloop
over the same object. Weird/unlikely situation, I know... but so is having a
deep break :D.

--
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie
Jun 27 '08 #1
0 602

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dennis M. Marks | last post: by
6 posts views Thread by Ritesh Raj Sarraf | last post: by
5 posts views Thread by tkpmep | last post: by
6 posts views Thread by noemailplease0001 | last post: by
5 posts views Thread by Kris Kowal | last post: by
6 posts views Thread by ccy56781 | last post: by
13 posts views Thread by Andrew | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.