Python Control Statements

Difference between Break and Continue in Python

Learn Difference between Break and Continue in Python with clear explanations, Python examples, and practical programming guidance.

What is the difference between break and continue?

Both statements change the normal flow of a loop. break ends the nearest loop completely, while continue skips only the current iteration and lets the loop process the next item.

The break statement

Use break when the loop should stop as soon as a condition is met:

for number in range(1, 11):
    if number % 2 == 0:
        break
    print(number)
Output
1

The loop prints 1, then stops when it reaches the first even number, 2. No later iterations run.

The continue statement

Use continue when one item should be ignored but the loop should continue:

for number in range(1, 11):
    if number % 2 == 0:
        continue
    print(number)
Output
1
3
5
7
9

Even numbers are skipped, but the loop continues until all numbers have been processed.

Comparison table

Featurebreakcontinue
PurposeStops the nearest loop.Skips the current iteration.
Later iterationsDo not run.Continue to run.
Control moves toThe first statement after the loop.The next iteration of the same loop.
Typical useStop after finding a result.Ignore invalid or unwanted items.
Works withfor and while loops.for and while loops.

Find the first matching item with break

Once the requested item is found, there is no need to inspect the remaining list:

languages = ["Java", "Python", "Go", "Rust"]

for language in languages:
    if language == "Python":
        print("Found:", language)
        break
Output
Found: Python

Ignore invalid values with continue

Continue processing valid values while skipping negative numbers:

numbers = [10, -2, 5, -8, 7]

for number in numbers:
    if number < 0:
        continue
    print(number)
Output
10
5
7

Using them in a while loop

When using continue in a while loop, update the counter before continuing. Otherwise, the condition may never change and the program may run forever:

number = 0

while number < 5:
    number += 1
    if number == 3:
        continue
    print(number)
Output
1
2
4
5

break, continue, and pass

StatementEffect
breakEnds the nearest loop immediately.
continueSkips the rest of the current iteration and starts the next one.
passDoes nothing and acts as a placeholder.

Key points for beginners

  • Use break to stop searching or processing.
  • Use continue to filter or ignore selected values.
  • Neither statement is used as a replacement for a condition; both normally appear inside an if block.
  • In nested loops, each statement affects only the nearest loop.

Further Reading

Continue learning with these related Python tutorials:

Continue learning