for: else: - any practical uses for the else clause?
Matthew Woodcraft
mattheww at chiark.greenend.org.uk
Fri Sep 29 18:42:01 EDT 2006
bjourne at gmail.com wrote:
> And so on. For every use of the for/else clause there exists a better
> alternative. Which sums up my opinion about the construct -- if you
> are using it, there's something wrong with your code.
How do you transform this?
height = 0
for block in stack:
if block.is_marked():
print "Lowest marked block is at height", height
break
height += block.height
else:
raise SomeError("No marked block")
-M-
More information about the Python-list
mailing list