Branching inside a loop
An IF placed inside a REPEAT is checked again on every repetition, so each pass through the loop can take a different path.
Understanding Branching inside a loop in Years 5–6 Creating Digital Solutions
What it does: If the light changes between passes, the IF picks stop on one pass and walk on another. The IF decides what happens on each pass, and the loop ends when the bag is full. In the correct answer the IF is indented under REPEAT, so it is inside the loop. In the other one the IF sits before the loop and is only checked once. Indented lines belong to the REPEAT above them. So the IF runs on every repeat. The IF is checked each time. Pass 2 is false, so the robot skips cleaning on that pass. The condition can be true on one pass and false on the next, so the path can change.
Common mistakes: Now both paths do the same thing, so the IF makes no difference. When the light is red the car should stop. The line should be: stop the car. We take apples out, so the bag gets emptier, not fuller. The loop would never stop. It should be: REPEAT UNTIL the bag is empty.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 21–30) and word search (Modules 21–40).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
IF inside REPEATFill in the Blanks
Spot the Error
Student with a class code? Join your class →