Loops in Python
Understand for and while loops with examples
Loops in Python is a free Python For Kids lesson on CoddyKit — 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, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Loops in Python
Welcome to the Control Flow lesson! Today, we'll learn about loops in Python, which help your programs repeat actions efficiently.

2
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.
3
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 item4
Example 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)
5
Output of the For Loop Example
When you run the above code, Python will print each fruit in the list:
apple
banana
cherry6
While Loops
The while loop repeats a block of code as long as a specified condition is true.
Syntax:
apple
banana
cherry7
Example 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 18
Output of the While Loop Example
Running the above code will display the numbers 1 through 5.
1
2
3
4
5
9
10
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!

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, and the Python For Kids course includes 4 lessons in total. 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.
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; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
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