First, ordinary logic is helpful.
If, for some reason, the terminating conditions can't be worked out, exceptions are a fall-back plan.
classGetOutOfLoop(Exception):passtry:
done=Falsewhilenot done:
isok=Falsewhilenot(done or isok):
ok = get_input("Is this ok? (y/n)")if ok in("y","Y")or ok in("n","N"):
done=True# probably betterraiseGetOutOfLoop# other stuffexceptGetOutOfLoop:pass
For this specific example, an exception may not be necessary.
On other other hand, we often have "Y", "N" and "Q" options in character-mode applications. For the "Q" option, we want an immediate exit. That's more exceptional.
http://www.keepmequiet.com/2015/12/10-keyboard-shortcuts.html