Control Structures: Difference between revisions

(→‎[[Python]]: with-statement)
Line 485:
bar()
baz()
else:
# break was not called
quux()
 
===for===
 
for i in range(10):
print i
else:
===try-except-else===
# break was not called
foo()
 
 
===try-except-finally-else===
 
'''Interpreter''': Python 2.5
 
Before Python 2.5 it was not possible to use finally and except together.
 
try:
Line 496 ⟶ 508:
except TypeError:
bar()
elsefinally:
baz()
else:
# no exception occurred
quux()
 
 
Line 504 ⟶ 519:
'''Interpreter''': Python 2.5
 
Imagine foo ascould for example open a file or creatingcreate a lock or a database transaction:
 
with foo() as bar:
Anonymous user