Learning how to use for loops in Python 3 is one of the most essential and frequently used skills at Progressive Robot — for loops let you iterate over sequences (lists, tuples, strings, dictionaries, ranges, files, etc.) in a clean, readable, and efficient way, making them perfect for processing data, generating reports, building automation scripts, training models, rendering UI elements, handling API responses, and almost every repetitive task in modern Python development.
In this up-to-date 2025–2026 Progressive Robot guide, you’ll master exactly how to use for loops in Python 3: basic syntax, range(), iterating different types (lists, strings, dicts, files), nested loops, break/continue/else, best practices, common patterns, and performance tips. All examples are tested on Python 3.10–3.13.
Key Takeaways – for Loops in Python 3
- For loops in Python 3 iterate over any iterable: for item in iterable: …
- Use range() when you need numeric sequences or known repetition count.
- Prefer for item in list: over for i in range(len(list)) — more Pythonic.
- Nested loops create 2D/3D structures (matrices, tables, combinations).
- break exits loop early, continue skips to next iteration, else runs if no break.
- enumerate() gives both index and value — very common pattern.
- for + else is powerful for “found/not found” logic.
- Avoid modifying list while iterating — use copy or list comprehension.
Prerequisites
- Python 3.8+ installed (Progressive Robot recommends 3.12+)
- Basic Python knowledge (variables, lists, print)
- Interactive shell (python3) or script file
1. Basic for Loop Syntax in Python 3
# Iterate over a list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I like {fruit}")
# Output:
# I like apple
# I like banana
# I like cherry
2. Using range() – Numeric Iteration
# 0 to 9
for i in range(10):
print(i, end=" ") # 0 1 2 3 4 5 6 7 8 9
# Start, stop, step
for i in range(5, 20, 3):
print(i, end=" ") # 5 8 11 14 17
# Reverse
for i in range(10, 0, -2):
print(i, end=" ") # 10 8 6 4 2
3. Iterating Different Types with for Loops in Python 3 Strings
word = "anaconda"
for letter in word:
print(letter, end=" ") # a n a c o n d a
Tuples & Sets
coords = (10.5, 20.8, 30.1)
for coord in coords:
print(coord)
Dictionaries (most common patterns)
user = {"name": "Zain", "city": "Karachi", "age": 30}
# Keys (default)
for key in user:
print(key)
# Values
for value in user.values():
print(value)
# Key-value pairs (recommended)
for key, value in user.items():
print(f"{key}: {value}")
4. Nested for Loops in Python 3
# Multiplication table 1–5
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} × {j} = {i*j:2d}", end=" ")
print() # new row
5. break, continue, else in for Loops
numbers = [1, 3, 5, 7, 9, 2, 4, 6, 8]
for num in numbers:
if num % 2 == 0:
print(f"Found even number: {num}")
break # exit loop immediately
else:
print("No even numbers found") # runs only if no break
continue example:
for num in range(10):
if num % 2 != 0:
continue # skip odd numbers
print(num, end=" ") # 0 2 4 6 8
6. enumerate() – Index + Value (Progressive Robot Favourite)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
fruits = ["apple", "banana", "cherry"]
for index, fruit in enumerate(fruits, start=1):
print(f"#{index}: {fruit}")
# Output:
# #1: apple
# #2: banana
# #3: cherry
7. Best Practices & Modern Tips (2025–2026 – Progressive Robot Style)
- Prefer for item in sequence: over for i in range(len(sequence))
- Use enumerate() when you need both index and value
- Avoid modifying list while iterating — use copy or comprehension
- Use for … else for “not found” logic — very clean
- Type hints: def process_items(items: list[str]) -> None:
- Combine with walrus operator (Python 3.8+): while (line := file.readline()): …
How to Use for Loops in Python 3 – FAQ (2025–2026)
- How do I use for loops in Python 3?
for item in iterable: — simplest & most common way to use for loops in Python 3. - What is range() used for in for loops in Python 3?
Generates numeric sequences: range(start, stop, step). - How do I get both index and value in for loops in Python 3?
for i, value in enumerate(sequence): — best practice. - What does the else clause do in for loops in Python 3?
Runs only if loop completes without break — great for search. - When should I use for vs while loops in Python 3?
for → known items/sequence; while → condition-based/unknown count.
Summary
You now know exactly how to use for loops in Python 3: basic syntax, range(), iterating lists/strings/dicts, nested loops, break/continue/else, enumerate(), and modern Progressive Robot best practices.
Mastering for loops in Python 3 unlocks clean iteration and data processing — essential for lists, files, APIs, databases, UI rendering, machine learning, automation, and almost every Python project.
Recommended Next Tutorials
- Python while Loops – Condition-Based Repetition
- break, continue, pass Statements in Python
- Python List Comprehensions (for + if in one line)
- Build a CSV Processor / Report Generator with for Loops
- Python Loops & Iteration Cheat Sheet