So I am in the process of learning python and I ran into this code that is confusing me.
var = 95
for items in range(0,100):
if var < 10:
continue
elif var == 10:
print("hit")
elif var > 10:
print("passed")
var = var + 1
I don’t understand why it doesn’t just print “passed” 5 times… instead it prints it like 100 times.
What exactly is continue doing? If I change var to like (3) will it just “continue” to the next code block?
continuecontinues to the next loop iteration. See the documentation.However, in this case it doesn’t matter, since the
oontinuewill never be reached.varstarts at 95 and can only increase, so it will never be less than 10.This code is a bit strange because only the last
elifwill ever execute. Perhaps you meant to usevarsomewhere in the loop?