🔄
💻 Technology ⏱ 3 min read

What is a Loop in Computer Programming?

Loops are instructions that tell computers to repeat tasks automatically, making code shorter and smarter.

Age 9–12
KS2 Computing KS3 Computing Ages 10-14
Reading level: |

What Exactly is a Loop?

A loop is a bit of computer code that tells a computer to do the same thing over and over again without you having to write it out each time. Instead of writing the same instruction 100 times, you write it once and tell the computer: "Repeat this 100 times." Loops are one of the superpowers of coding because they save time and make programs much simpler.

Think of it like washing the same plate over and over. Instead of saying "wash the plate, rinse the plate, dry the plate, wash the plate, rinse the plate, dry the plate..." you could say "repeat these three steps until all the plates are clean."

Why Do Programmers Use Loops?

Imagine you want to list the numbers from 1 to 1000 on your screen. Without a loop, you'd have to write 1000 lines of code. That's crazy! With a loop, you write maybe 3 lines and the computer does the rest. Loops make programmes faster to write, easier to understand, and less likely to have mistakes in them.

Two Main Types of Loops

There are two popular kinds of loops that programmers use all the time. The first is called a "for" loop. This loop runs a set number of times—you tell it exactly how many times to repeat something. The second is called a "while" loop. This one keeps going as long as something is true. For example, a while loop might say: "Keep asking the user for a password while they keep getting it wrong."

A "for" loop is like saying "do 10 jumping jacks." You know exactly when you'll stop. A "while" loop is like saying "keep jumping until you get tired"—you don't know the exact number, just the stopping condition.

Loops in Real Life

Loops are everywhere in the digital world. When Netflix shows you a list of films to watch, that's a loop going through every film in a category. When your game checks if you've scored a goal over and over every second, that's a loop. Even when your phone updates every message in a chat, loops are doing the work behind the scenes. Understanding loops is one of the first steps towards becoming a real programmer!

Test yourself 🧠

This quiz is calibrated for KS2 Computing.