return in loop for ?

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


yomgui <not at valid.org> 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()
11
>>> 

    <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list