Kids Coding
Repeat (Loops)
A for loop repeats work. Count. Print a pattern. Stop when you are done.
Do it more than once
A for loop repeats a block. range(5) means five times: 0, 1, 2, 3, 4.
Count
for n in range(5):
print(n)Print a word many times
Five hellos
for n in range(5):
print("hello")Count from 1
range(1, 6) starts at 1 and stops before 6. So you get 1, 2, 3, 4, 5.
1 to 5
for n in range(1, 6):
print("Number", n)The second number in range is the stop sign. Python does not include it.
Real life
Walking up the stairs and counting each step.
You do not write “step” twelve times. You repeat. A loop is the count.
Twelve stairs
for step in range(1, 13):
print("Step", step)
print("At the top")Change one word. Run it. That is how this idea shows up outside the lesson.
Try it
Exercise 1: Print Go! exactly three times using a loop.
Show solution
for n in range(3):
print("Go!")