Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Loop Control Statements .docx59.2 KB Loop Control Statements - Solution.docx
59.1 KB
Quick reference
Loop Control Statements
Loop control statements give you fine tuning control of your loop.
When to use
Use them whenever you need to interrupt a loop.
Instructions
The break statement stops a counter if a condition is met.
count = 0
while (count < 10):
print(count)
count += 1
if (count == 5):
break
The continue statement restarts a loop if a condition is met.
count = 0
while (count < 10):
count += 1
if (count == 5):
continue
print(count)
The pass statement allows us to pause our loop if a condition is met, and then continue right where we left off.
for letter in "John":
if (letter == "h"):
pass
print("This is a pass!")
print(letter)
Hints & tips
- Loop control statements let you interrupt a loop
- Loop control statements are: break, continue, and pass
Lesson notes are only available for subscribers.