Skip to main content
Practice

Loop Controls (break, continue, pass)

Loops let us repeat code — but sometimes we need more control. What if you want to exit a loop early, skip part of it, or leave space for future logic?

Python provides three helpful keywords: break, continue, and pass.

Let’s go through each of them with examples.


1. break: Stop the Loop Immediately

Use break when you want to exit the loop entirely, no matter how many items are left.

for number in range(1, 10):
if number == 5:
break
print("Number:", number)

Explanation:

  • This loop prints numbers from 1 to 9.
  • But when number == 5, it hits break and exits the loop.
  • So the output is: 1, 2, 3, 4

2. continue: Skip the Current Step

Use continue when you want to skip one iteration and move on.

for number in range(1, 6):
if number == 3:
continue
print("Number:", number)

Explanation:

  • This skips number == 3, but keeps looping.
  • Output is: 1, 2, 4, 5

3. pass: Placeholder That Does Nothing

pass is used when you need a block of code syntactically, but don’t want to write anything yet.

for letter in "data":
if letter == "t":
pass
print("Letter:", letter)

Explanation:

  • When letter == "t", the program does nothing — just moves on.
  • This is useful as a placeholder for future logic.

Summary

KeywordWhat It Does
breakExits the loop completely
continueSkips to the next loop iteration
passDoes nothing (used as placeholder)

What’s Next?

Up next, you’ll learn how to define and use functions — an essential skill for writing clean, reusable Python code.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.