Thinking Like a Programmer•Interactive notebook lesson•Free
break continue pass
No account is required. Learn the material, try the examples, and mark it complete locally when you are ready to move on.
Break Continue Pass
Codepython
counter = 10
while counter > 5:
# IF the counter is 7, break out of the loop
if counter == 7: break
print(f"the value of counter: {counter}")
counter -= 1 # Same as saying counter = counter - 1
Output
the value of counter: 10
the value of counter: 9
the value of counter: 8
Codepython
counter = 10
while counter > 5:
counter -= 1 # Same as saying counter = counter - 1
# IF the counter is 7, dont do anything for that value or loop
# when ccounter is 7, skip to next loop
if counter == 7: continue
print(f"the value of counter: {counter}")
Output
the value of counter: 9
the value of counter: 8
the value of counter: 6
the value of counter: 5