Loops in Python
Understand for and while loops with examples
Loops in Python is a free Python For Kids lesson on CoddyKit. This is lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python For Kids learning path, and your progress syncs across the web and the CoddyKit app. The Python For Kids course includes 4 lessons in total.
Introduction to Loops
Loops in Python
Welcome to the Control Flow lesson! Today, we'll learn about loops in Python, which help your programs repeat actions efficiently.

What are Loops?
Loops allow your program to execute a block of code multiple times without having to write the same code repeatedly. They are essential for tasks that require repetition.
- For Loops: Iterate over a sequence of items.
- While Loops: Repeat as long as a condition is true.
For Loops
The for loop is used to iterate over a sequence (like a list, tuple, or string) and execute a block of code for each item in the sequence.
Syntax:
for item in sequence:
# code to execute for each itemExample of a For Loop
Let's see how a for loop works with a simple example.
Example:
# Iterates over each fruit in the list and prints it
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Output of the For Loop Example
When you run the above code, Python will print each fruit in the list:
apple
banana
cherryWhile Loops
The while loop repeats a block of code as long as a specified condition is true.
Syntax:
apple
banana
cherryExample of a While Loop
Here's how a while loop works with a simple example.
Example:
# Prints numbers from 1 to 5
count = 1
while count <= 5:
print(count)
count += 1 # Increments count by 1Output of the While Loop Example
Running the above code will display the numbers 1 through 5.
1
2
3
4
5
Great Job!
You've learned how to use for and while loops to repeat actions in your Python programs. Loops help make your code more efficient and powerful. Keep practicing by creating your own loops and exploring different scenarios!

Learn Python with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 22
- Lessons
- 94
Frequently Asked Questions
Is the “Loops in Python” lesson free?
Yes — the full text of “Loops in Python” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python For Kids course, upgrade to CoddyKit PRO. The Python For Kids course includes 4 lessons in total.
What will I learn in “Loops in Python”?
Understand for and while loops with examples You practise Python For Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python For Kids?
No prior experience is required. Python For Kids on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “Loops in Python” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python For Kids lesson?
Yes. Every Python For Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- If-Else Statements
- Loops in Python
- Nested Loops
- Break and Continue