for-else

castironpi at gmail.com castironpi at gmail.com
Tue Mar 4 13:40:11 EST 2008


Would you like it to be removed or its name changed?

You can do it with a special iteration:

for a in B:
   if behavior
      break
else:
   2behavior

---->

class KeepResult:...
kr= KeepResult( B )
for a in kr:
   if behavior
      break
if kr.diditbreak?:
   2behavior
(if not:
   3behavior)

It just can't do automatic continues; you'd need a
kr.i'mcontinuingonthisone().  Would that be useful in addition?



More information about the Python-list mailing list