- Home
- /
- Python Control Statements
Python Tutorial
Introduction
Python Data Types & Oper...
Python Strings
Python Lists
Python Tuples
Python Sets
Python Dictionaries
Conditional Statements
Python Loops
Python Functions
Python Modules
Python OOPS
Advanced Topics
File Handling
- Home
- /
- Python Control Statements
Control Statements
Sometimes, we need to control how a loop behaves—whether to skip something, stop completely, or just hold a place for now. Python gives us three keywords that do this job inside loops:
pass
continue
break
Let’s see how each one works with real examples.
1. pass – Do Nothing (For Now)
Python expects some code inside every block—whether it’s an if
condition, loop, or function. If you leave it empty, it will raise an error. To avoid this, you can use the pass
statement as a placeholder.
Example:
day = 1
while day <= 5:
pass # We'll add the code here later
for subject in ['Math', 'English', 'Science']:
pass # Placeholder for future logic
if day == 3:
pass # Still deciding what to do on day 3
These won’t produce errors even though nothing is actually happening..
2. continue – Skip This One, Move On
If you want to skip a specific iteration in a loop and move to the next one, use continue
.
Example 1: Skip multiples of 3
for num in range(1, 10):
if num % 3 == 0:
continue
print(num)
Output:
1
2
4
5
7
8
Example 2: Skip odd numbers using a while loop
count = 0
while count < 10:
count += 1
if count % 2 != 0:
continue
print(count)
Output:
2
4
6
8
10
3. break – Stop the Loop Immediately
Sometimes you want to exit the loop entirely, even if it hasn’t finished. That’s what break
does.
Example 1: Exit loop when value is 4
for num in range(1, 10):
if num == 4:
break
print("Counting:", num)
Output:
Counting: 1
Counting: 2
Counting: 3
Example 2: Break a while loop early
value = 1
while value <= 10:
print("Value is:", value)
if value == 5:
break
value += 1
Output:
Value is: 1
Value is: 2
Value is: 3
Value is: 4
Value is: 5
Summary
pass
→ do nothing (useful when writing code structure).continue
→ skip the current loop run.break
→ exit the loop completely.
These three tools give you more control over how your loops behave in real-time.