Repeating Things: How Loops Work Think about brushing your teeth. You do not brush once and stop. You brush, and brush, and brush again — the same movement, over and over — until two minutes are done or your arm gets tired. That repeating action has a name in programming. It is called a loop . What is a Loop? A loop is simple: do something again and again . But every loop also needs an answer to one question: when do you stop? There are two easy ways a loop knows when to stop: Way 1: Do it a certain number of times "Clap your hands 10 times ." You know exactly when to stop — after clap number 10. You count as you go. Way 2: Keep going UNTIL something happens "Keep walking UNTIL you reach the door." You do not know how many steps it will take. You just keep going and check — am I at the door yet? The moment the answer is yes, you stop. Both of these are loops. They just have different stopping rules. Loops You See Every Day Brushing Teeth > Move the brush up and down → move the brush up and down → move the brush up and down… STOP when: 2 minutes are done (your timer beeps) This is a "keep going UNTIL" loop. You do not count your strokes — you just go until the timer tells you to stop. Eating Crisps from a Packet > Take a crisp → eat it → take another crisp → eat it → take another… STOP when: the packet is empty No counting needed. You just keep going and stop when there is nothing left. The School Bell A school rings the bell at the start of each period. How many times does it ring in a day? > Ring the bell → wait 45 minutes → ring the bell → wait 45 minutes → ring the bell… STOP when: 8 periods are done (the school day ends) This is a counting loop — it rings exactly 8 times, then stops. The Blinking Festival Lights Those decorative lights that blink around Diwali or Christmas? They follow a simple pattern: on, off, on, off, on, off… > Turn ON → wait → turn OFF → wait → turn ON → wait… STOP when: someone switches off the plug Until someone stops it, they just keep blinking forever. Some loops do not stop on their own — they run until you switch them off. The Magic of Loops Here is why loops matter. Imagine you want to say "Happy Birthday!" to every student in your school — 600 people. Without a loop: say it once, say it twice, say it a third time… 600 separate instructions. With a loop: say "Happy Birthday!" — and repeat that 600 times . Same result. But the loop version takes one instruction instead of 600. Computers use this to do enormous amounts of work incredibly fast. A computer can repeat something a million times in less than a second — without getting bored, without forgetting, without making a mistake after repetition. Two Questions for Every Loop Before a computer runs any loop, it needs answers to two things: 1. What should it repeat? (The action) 2. When should it stop? (The stopping rule — either a count or a condition) Without the stopping rule, the loop runs forever. That is called an infinite loop — and it is the kind of mistake that freezes programs. Always know how your loop stops. The Three Ideas So Far Idea What it means Simple example ------ --------------- ---------------- Sequence Follow steps in order Traffic signal: Red → Yellow → Green (always in that order) Decision Do different things based on a condition News ticker: if breaking news → red banner Loop Repeat steps, stop when the rule says so School bell rings 8 times, one per period In the final post, we put all three together and see how every program ever written — no matter the size — uses exactly these ideas. Did you know? A modern phone chip can repeat a simple instruction roughly a billion times per second . If you tried to do one of those steps every second yourself, without ever sleeping, it would take you about 32 years to match one second of your phone. 🎯 Try This Yourself Hunt the Loop Loops are hiding all over your day. Go and find them. 1. Take one hour of your life — getting ready for school, or dinner time. 2. Write down every action you repeat. Chewing. Climbing stairs. Scrolling. Stirring. 3. For each one, answer the one question every loop must answer: how do you know when to stop? 4. Sort them into two piles: "stop after counting to a number" and "keep going UNTIL something happens" . What to watch for: the "until" pile is almost always bigger. Now find one loop with no stopping rule at all — a fan, a clock, a fridge. Those run until someone pulls the plug. A computer with a loop like that by accident is said to have frozen . 🤔 Check Yourself 1. What are the two things every loop needs? What to repeat (the action) and when to stop (the stopping rule — either a count, or a condition to watch for). 2. "Keep taking crisps until the packet is empty." Counting loop, or until-loop? An until-loop . You have no idea how many crisps are in there — you just keep checking "is it empty yet?" after each one. 3. What is an infinite loop, and why is it a problem? A loop with a stopping rule that never becomes true, so it…