I'm using a loop and a nested loop, and i need the outer loop to stop whenever the second reaches a certain value.
for first in range(0,10):
for second in range(0,10):
print(first second)
But i want it to skip to the next 'first' value if the second value is odd.
I tried to do something like this:
odd = [1,3,5,7,9]
for first in range(0,10):
for second in range(0.10):
if second in odd:
continue
But it won't work.
CodePudding user response:
break
breaks out of the inner loop only, which jumps to the after the inner loop. Assuming that there’s no code immediately after the inner loop, then the current iteration of the outer loop will end and the next one will start.
So I think using break
instead of continue
should do exactly what you want.
CodePudding user response:
To terminate a loop you should use break. Try using break instead of continue