return in loop for ?

Mike Meyer mwm at
Thu Nov 24 00:55:13 CET 2005

yomgui <not at> writes:
> is it legal to return inside a for loop
> or am I obliged to break out of the loop before returning ?

Try it and see:

>>> def f():
...  for i in range(20):
...   if i > 10: return i
>>> print f()

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list