Many Python programmers are probably unaware that the syntax of
for val in iterable:
(This is inspired by @Mark Tolonen's answer.)
if statement runs its
else clause if its condition evaluates to false.
while loop runs the else clause if its condition evaluates to false.
This rule matches the behavior you described:
breakstatement, you exit out of the loop without evaluating the condition, so the condition cannot evaluate to false and you never run the else clause.
continuestatement, you evaluate the condition again, and do exactly what you normally would at the beginning of a loop iteration. So, if the condition is true, you keep looping, but if it is false you run the else clause.
return, do not evaluate the condition and therefore do not run the else clause.
for loops behave the same way. Just consider the condition as true if the iterator has more elements, or false otherwise.