I want to run a function (def) 100 times using while (with numbers from 0 - 1000000)
But the while doesn't break the loop when needed.
How can I fix it?
count = 2 #I start from 2 on purpose
limit = 101
def is_prime(i):
global count
count+=1
#there is more to the function is_prime but it isn't relevant
#i made a function with input to show a example
while (count < limit):
for i in range(1000000):
is_prime(i)
print ("count = ", count)
I expect it to stop when it gets to count = 100
forloop does not care about the exit strategy of the outer while loop, thus it will go on until it reaches the end (range(1000000)in your case ) and then thenwhileloop exits.