Python return statement error " 'return' outside function"

Solution 1:

The return statement only makes sense inside functions:

def foo():
    while True:
        return False

Solution 2:

Use quit() in this context. break expects to be inside a loop, and return expects to be inside a function.