I have this code that prints first ten elements of the list and then prints end:
a = ["11","12","13","14","15","16","17","18","19","110"]
n = 0
limit= 10
while n != limit:
for b in a:
if "1" in b:
print(b)
n += 1
print("end")
I am trying to figure out why it breaks if I add more numbers to the list.
a = ["11","12","13","14","15","16","17","18","19","110","111","112"]
n = 0
limit= 10
while n != limit:
for b in a:
if "1" in b:
print(b)
n += 1
print("end")
Goes on forever, printing the numbers again and again. Can someone explain why?
I have already replaced it with this but I just want to understand what was wrong with the first one.
a = ["11","12","13","14","15","16","17","18","19","110","111","112"]
n = 0
limit= 10
for b in a:
if "1" in b:
print(b)
n += 1
if n == limit:
break
print("end")
What was wrong with it?