Code highlights logo




Imagine you have a chore to do, like watering the plants. Instead of going to each plant and saying, "Okay, time to water this one," then going to the next and saying it all over again, wouldn't it be easier if you could just repeat "water the plant" until all the plants are happy? In the world of coding, we have a magical trick for this, and it's called a "loop."

A loop is a way to tell the computer, "Hey, do this thing over and over again until something tells you to stop." It's like having a smart robot that knows to water each plant without you having to tell it every single time.

For example, let's say you have a list of your top ten favorite cartoons. If you want to watch each one once a week, instead of writing out "watch this cartoon" ten times, you could use a loop in programming to say "watch each cartoon in the list," and it would understand to do that for all ten cartoons.

Here's what you need to remember about loops:

  • Looping means to repeat something.
  • We use loops to make our code smarter and not have to repeat ourselves.
  • Loops keep going until we tell them to stop (just like your robot would keep watering the plants until all of them are done).
  • It's a way to make the computer do a lot of work without a lot of code.

By the end of our lesson, you'll be able to tell your computer to do lots of things over and over again, like a magic spell for repeating tasks!

Sign up to start coding

Already have an account?

Sign In

Course content