LEARN Python - 3.1 For Loops - The Organized Repeater - zerotopyhero.com

Learn Python – 3.1: For Loops – The Organized Repeater

Teaching Python How to Repeat Things Without Losing Count

Loops are Python’s way of saying:

“I’ve got this. Go get a coffee.”

And for loops are the most polite, organized version of that.

You use a for-loop when you already know how many times something should happen, or when you want to go through a collection of things one by one.

No guessing.
No chaos.
Just calm repetition.

The Simplest For Loop

Let’s start with a tiny example:

				
					for i in range(5):
     print("Hello!")

				
			

Run it, and you’ll see:

				
					Hello!
Hello!
Hello!
Hello!
Hello!
				
			

Python printed the message five times, even though you only wrote it once.

That’s the whole point.

Reading a For Loop Like a Human

That line might look a bit strange at first, so let’s read it in plain English:

“For each number in the range from 0 up to (but not including) 5, do this.”

The indented code runs once per loop.

If you can read it like a sentence, you’re already most of the way there.

What Is range()?

range() is Python’s built-in counting tool.

				
					range(5)
				
			

Does not mean:

“From 1 to 5”

It means:

“0, 1, 2, 3, 4”

Python loves starting at zero.
You’ll get used to it.

You can see it in action:

				
					for i in range(5):
     print(i)
				
			

Output:

				
					0
1
2
3
4
				
			

That i is just a variable name.
It changes each time the loop runs.

The Loop Variable (i)

In this loop:

				
					for i in range(5):

				
			

i takes on a new value every time:

  • First loop → i is 0

  • Second loop → i is 1

  • Third loop → i is 2
    …and so on.

You can use i inside the loop:

				
					for i in range(5):
     print(f"This is loop number {i}")

				
			

Python keeps track of the counting for you.

Custom Ranges (Starting Somewhere Else)

You don’t have to start at 0.

				
					for i in range(1, 6):
     print(i)

				
			

Output:

				
					1
2
3
4
5
				
			

Here’s the rule:

				
					range(start, stop)
				
			
  • start → included

  • stop → not included

Yes, that “stop not included” thing again.
Same rule as slicing.
Same confusion.
Same consistency.

Changing the Step Size

You can also tell Python how much to jump each time:

				
					for i in range(0, 10, 2):
     print(i)
				
			

Output:

				
					0
2
4
6
8
				
			

That’s:

				
					range(start, stop, step)
				
			

Python counts by step instead of 1.

Why For Loops Are So Useful

For-loops shine when you want to:

  • Repeat something a known number of times

  • Count up or down

  • Build patterns

  • Process collections later (lists are coming soon)

They’re predictable.
They’re controlled.
They don’t surprise you.

Perfect beginner material.

A Friendly Example

				
					name = input("What's your name? ")

for i in range(3):
    print(f"Nice to meet you, {name}!")

				
			

Python politely greets the user three times.
No copy-pasting required.

Common Beginner Questions (Answered)

“Why is it called i?”
It doesn’t have to be. i is just a tradition.
You could write:

				
					for count in range(5):

				
			

Python doesn’t care. i is just standard in Python. i is for index. You can use anything that makes more sense for you.

“Does the loop stop by itself?”
Yes. When range() runs out of numbers, the loop ends automatically.

“What if I mess up the indentation?”
Python will tell you immediately.
And that’s a good thing.

What You’ve Learned

You now know:

  • What a for-loop is

  • How range() works

  • Why counting starts at zero

  • How repetition is controlled

  • How Python repeats code safely

This is a huge unlock.

Mini Quiz

Try these:

  1. How many times does this loop run?

				
					for i in range(4):
     print("Hi")
				
			

     2. What numbers does this print?

				
					for i in range(2, 7):
     print(i)
				
			

     3. What does the i variable represent?

     4. Why does range(5) stop at 4?

     5. What would you change to make the loop run 10 times?

Coming Up Next

For-loops are great when you know how many times to repeat.

But what if you don’t?

What if you want Python to keep going until something changes?

ZeroToPyHero