while doesn’t break when i>10 in for loop:
i = 0
x = 100
while i<=10:
for a in xrange(1, x+1):
print "ok"
i+=1
and it prints "ok" 100 times. How to break the while loop when i reaches 10 in for loop?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Until the inner loop "returns", the condition in the outer loop will never be re-examined. If you need this check to happen every time after
ichanges, do this instead:That
breakwill only exit the inner loop, but since the outer loop condition will evaluate toFalse, it will exit that too.