A for loop is a way to repeat a block of code a certain number of times. Instead of writing the same instruction over and over, you can tell Python: “Do this for every item in a list” or “Repeat this action five times.”
For loops are very useful when working with collections of data, like lists of names, or when you want to repeat something in a neat, controlled way.
The basic idea
A for loop moves through a sequence (like a list, a string, or a range of numbers) and runs the code once for each item.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Output:
apple
banana
cherry
Using ranges
If you just want to repeat something a certain number of times, use range().
for i in range(5):
print("Hello")
This will print "Hello" five times.
Useful things to try
- Print every letter in the word
"Python". - Write a loop that prints numbers from 1 to 10.
- Create a list of your three favourite foods and print each one.
- Use
range(2, 11, 2)to print even numbers between 2 and 10.
Summary
- A for loop repeats code for each item in a sequence.
- It is ideal for working with lists, strings, or ranges of numbers.
- It helps avoid repeating yourself in code and makes your programs shorter and clearer.





