On Mon, 28 Sep 2009 22:09:37 -0500
Peng Yu <[email protected]> wrote:
> I want some command to jump out of nested loop. I'm wondering what is
> the most convenient way to do so in python.
Forget about jumping out of a loop. Put your loop into a function and
simply return. Much cleaner and clearer.
> for i in range(10):
> print "i = ", i
> for j in range(10):
> if i*10 + j == 50:
> print i*10 + j
> break # I want to jump out of the loops.
def myfunc(li, lim, mul):
for i in li:
print "i = ", i
for j in range(10):
if i*mul + j == lim:
return i*mul + j
print myfunc(range(10), 50, 10)
--
D'Arcy J.M. Cain <[email protected]> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list