Python: ‘break’ outside loop

Because break cannot be used to break out of an if – it can only break out of loops. That’s the way Python (and most other languages) are specified to behave.

What are you trying to do? Perhaps you should use sys.exit() or return instead?

Leave a Comment