[Tutor] for loop

john fleming fleming.j at comcast.net
Wed Jan 7 22:09:13 EST 2004


This is Guatavos solution to Ron's loop:

x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]]
for num in x:
   if 5 in num:
       print 'yes'
       break
This is Loyds solution:
if 5 not in x[0]:
    print "yes"
This was mine:
x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]]

for num in x:
    if 5 not in num:
        print 'yes'   

What is the advantage to using break as in gustavo's code?





More information about the Tutor mailing list