In Python, you can put an else statement after try-except, for, and while. After a try-except, it'll be executed if there was no exception; after a for or a while it'll be executed if there was no break out of the loop. For example, this allows the following fairly common idiom:
for whatever in something:
if meetsCondition(whatever):
result = whatever
break
else: print "Couldn't find something that meets the condition"
Unfortunately, it's not possible to use elif instead. I think that this is an oversight, and it'd be a lot easier for beginners to learn the language if try-except, for, and while just acted as though they were if variants. It would allow the example above to be extended to something like the following:
for whatever in something:
if meetsCondition(whatever):
result = whatever
break
elif options.verbose:
print "Couldn't find something that meets the condition"
Instead of doing:
...
else:
if options.verbose:
print "Couldn't find something that meets the condition"
Which is ugly and inconsistent. It would only require a very trivial change to the grammar, and complements the try-except reforms proposed in PEP 341 nicely. See also the conversation that led to these musings.
⚜ ⚜ ⚜
Incidentally, Kevin Reid (for whom the section-dividing fleurs-de-lis above are intended, though not many fonts seem to contain them) pointed out that the else syntax above is not all that intuitive anyway, and that in the case of a for loop could easily be misconstrued as only executing when there were no iterations in the loop.
If this were taking place in a non-Python language, a language where the global variable space and the user variable space were separate, I'd drop various facts about the loop into the global variable space. For example, "broken" could be set to true if the loop was broken out of; "iterations" could contain the number of iterations that the loop had; and there could be lists of exceptions caught, and so on.