06
Phase 2 - Level 1: Basic Looping
Chapter 6 • Beginner
60 min
Phase 2 - Level 1: Basic Looping
Introduction to Loops
Loops allow you to repeat code multiple times. They are essential for processing collections, iterating through data, and automating repetitive tasks.
Types of Loops
For Loop
Used when you know the number of iterations:
python.js
for i in range(start, end, step):
# Code to repeat
While Loop
Used when iteration depends on a condition:
python.js
while condition:
# Code to repeat
Range Function
range(n): 0 to n-1range(start, end): start to end-1range(start, end, step): with step size
Common Patterns
- Print numbers in sequence
- Calculate sums and products
- Iterate through collections
- Count occurrences
Key Concepts
- Iteration: Repeating code multiple times
- Loop Variable: Variable that changes each iteration
- Range: Sequence of numbers to iterate over
- Accumulation: Building up values (sum, product)
Hands-on Examples
Print Numbers 1 to 10
# Print numbers 1 to 10
for i in range(1, 11):
print(i)range(1, 11) generates numbers from 1 to 10. The loop variable i takes each value and prints it.
Related Tutorials
🔗Related Content
- 💻
Phase 2 - Practice Problems
Practice Phase 2 concepts with hands-on coding problems
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with assessment questions
- ➡️
Phase 3 - Get Started
Continue to Phase 3 after mastering Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum