Break & Continue in Python
-
This lesson explains how break stops a loop and continue skips an iteration in Python.
What are Loop Control Statements?
Loop control statements are used to change the normal flow of a loop.
They allow us to:
Stop a loop
Skip an iteration
Do nothing temporarily
Python provides three loop control statements:
break
continue
pass
1️.break Statement
The break statement is used to immediately stop a loop, even if the loop condition is still True.
👉 When break executes, the loop terminates and control moves outside the loop.
Syntax
break
Flow Behavior
Loop starts → condition checked → break occurs → loop stops
Stopping Loop Using break
This program stops the loop when the number becomes 3 using the break statement.
for i in range(1, 6):
if i == 3:
break
print(i)
Using break in while Loop
This program terminates the loop when the count reaches 4.
count = 1
while count <= 5:
if count == 4:
break
print(count)
count += 1
Common Uses of break
Search operations
Exiting infinite loops
Stopping loops on condition match
2️.continue Statement
The continue statement is used to skip the current iteration of the loop and move to the next iteration.
👉 The loop does not stop, only the current step is skipped.
Syntax
continue
Flow Behavior
Loop starts → condition checked → continue occurs → next iteration
Skipping Iteration Using continue
This program skips printing number 3 using the continue statement.
for i in range(1, 6):
if i == 3:
continue
print(i)
Using continue in while Loop
This program skips even numbers while printing odd numbers.
num = 0
while num < 6:
num += 1
if num % 2 == 0:
continue
print(num)
Common Uses of continue
Skipping unwanted values
Filtering data
Avoiding complex if blocks
3️.pass Statement
The pass statement is a null statement.
It does nothing when executed.👉 It is used as a placeholder where a statement is required syntactically, but no action is needed.
Syntax
pass
Using pass in Loop
This program uses pass as a placeholder inside a loop.
for i in range(1, 6):
if i == 3:
pass
else:
print(i)
Using pass in if Statement
This program shows how pass can be used when logic is not yet implemented.
age = 16
if age >= 18:
pass
else:
print("Not eligible to vote")
Common Uses of pass
Empty loops or conditions
Future code implementation
Avoid syntax errors
Key Differences: break vs continue vs pass
Notes
break exits the loop immediately
continue skips the current iteration
pass is a placeholder statement
All are used to control loop behavior
Where These Are Used?
Searching and filtering
Validation logic
Menu-driven programs
Loop control and debugging