By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

Re: PEP on breaking outer loops with StopIteration

P: n/a

Quoting Kris Kowal <kr********>:
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
Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.