M
Matthew Fitzgibbons
Paul said:Close, but there is no reason for the conditions to raise anything,
they can just use the continue statement:
i = 20
while i > 0:
try:
if i % 2:
continue
if i % 3:
continue
print i, "is even and a multiple of 3"
finally:
i -= 1
Prints:
18 is even and a multiple of 3
12 is even and a multiple of 3
6 is even and a multiple of 3
I think this is closest to the OP's stated requirements.
-- Paul
I'm aware my example where I raised exceptions was functionally
different ("This will bail out of the loop on an exception and the
exception will get to the next level.") Just thinking in terms of
telling the caller something went wrong. The other examples were
functionally equivalent, however.
Still, this is the best way so far. I never thought of using continue
with finally. It gets added to my Python tricks file for future use.
-Matt