When running the following code (in Python 2.7.1 on a mac with Mac OS X 10.7)
while True:
return False
I get the following error
<To break a loop, use break
instead of return
.
Or put the loop or control construct into a function, only functions can return values.
As per the documentation on the return statement, return
may only occur syntactically nested in a function definition. The same is true for yield.
The return statement only makes sense inside functions:
def foo():
while True:
return False
Use quit()
in this context. break
expects to be inside a loop, and return
expects to be inside a function.