Repeating Instructions
Sometimes we need to do the same thing many times. A loop is a clever shortcut!
Doing Things Again and Again
Sometimes we need to do the same thing many times. Look at this:
Jump! Jump! Jump! Jump!
That's 4 jumps. But writing "jump" 4 times takes a long time!
Is there a shorter way to say it? Yes, there is!
The Short Way: Loops
Instead of writing "jump" 4 times, we can say "Jump 4 times." That's much easier!
The Long Way
Jump!
Jump!
Jump!
Jump!
(4 lines!)
The Short Way (A Loop!)
Jump 4 times.
(Just 1 line!)
This is called a loop because the instruction goes around and around. A loop is a shortcut!
Loops in Real Life
You use loops in real life all the time! A loop repeats the same instruction.
Not a loop: Singing "Happy Birthday" has different lines each time. A loop repeats the same instruction!
Loops Save Time
Imagine telling a robot to take 100 steps. Would you write "step" 100 times? No way! You'd say "Take 100 steps."
Computers use loops because loops save time and effort. One short instruction can do a big job!
Loops are one of the most important ideas in coding. They let computers do huge tasks without huge instructions!
Think About It
1. Can you think of something you do the same way every single morning?
2. If a robot needed to draw a square, what instruction would it repeat? How many times?
3. Why would a loop be useful for a computer drawing 50 stars?
Knowledge Check
Choose the correct answer for each question. Click "Check Answer" to see if you are right!
Question 1
What is a loop?
Question 2
Instead of saying "clap, clap, clap, clap, clap" we can say...
Question 3
Which of these is an example of a loop?
Question 4
Why do computers use loops?
Question 5
"Hop 3 times" -- how many hops is that?
Key Concepts Summary
- ●A loop repeats the same instruction a set number of times.
- ●Loops are a shortcut -- they save us from writing the same thing over and over.
- ●"Jump 4 times" is a loop because it repeats "jump".
- ●Computers use loops to do big jobs quickly.