← Back to course
Loops: Don't Repeat Yourself
The trick
Imagine telling a computer to print "Happy Birthday" 100 times. Writing it 100 times would be silly — so we use a loop: an instruction that says "repeat this a certain number of times" (or "repeat until something happens"). Loops let a few lines of code do a huge amount of work, which is one of the reasons computers are so powerful. But beware the infinite loop — a loop with no way to stop will run forever and freeze the program. A good loop always has a clear ending condition: "repeat 10 times," or "repeat until the score reaches 100."
Worked examples
🧩 Unplugged activity: Instead of writing "clap" 20 times, write it as a loop in plain words: "Repeat 20 times: clap." Now do the same for a chore you repeat — "Repeat until the floor is clean: sweep."
Practice
…