T
Thomas Boell
Examples:
# else branch will be executed
i = 0
while i < 5:
i += 1
else:
print('loop is over')
# else branch will be executed
i = 0
while i < 5:
i += 1
if i == 7:
print('i == 7')
break
else:
print('loop is over')
# else branch wont be executed
i = 0
while i < 5:
i += 1
if i == 3:
print('i == 3')
break
else:
print('loop is over')
Huh?! I would have expected all your examples to raise a SyntaxError or
IndentationError. Why don't they? Is 'else' not required to have a
matching 'if'?