Module 5: Python Conditions and LoopsBeginner18 min read
For Loops & Range
Iterating through sequences, strings, ranges, and using break/continue.
Key Takeaways & Core Concepts
break: Terminate loop prematurely.continue: Skip the rest of current iteration and jump to next.
For Loops & Range
### For Loops in Python
A for loop in Python is used for iterating over a sequence (such as a list, tuple, dictionary, set, or string).
PYTHON Code Example
1courses = ["Python", "FastAPI", "React", "Docker"]
2for course in courses:
3 print("Enroll in:", course)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
3 lines
#### The range() Function To loop through a set of code a specified number of times, use range(start, stop, step):
PYTHON Code Example
1# Prints 0 through 4
2for i in range(5):
3 print(i)
4
5# Prints 10, 20, 30, 40
6for i in range(10, 50, 10):
7 print(i)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
7 lines
#### Control Flow: break and continue
break: Terminate loop prematurely.continue: Skip the rest of current iteration and jump to next.
Filtering with Continue
1for n in range(1, 10):
2 if n % 2 != 0:
3 continue
4 print(f"Even: {n}")
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
4 lines
Note: The continue statement bypasses the print call when n is odd.
Practice & AssessmentPython Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)