← Years 5–6 Creating Digital Solutions

Decisions inside loops in a visual program

An if block placed inside a loop is checked again on every repeat, so the program makes a new decision each time round, like in forever or repeat until.

Understanding Decisions inside loops in a visual program in Years 5–6 Creating Digital Solutions

What it does: The if is placed inside forever, so the sprite checks for red again and again. Each repeat tests the if block for the enemy, while the loop itself stops when lives = 0. Only blocks inside the loop are repeated. To keep watching the keyboard, the if must go inside the forever block. Checking the condition on every repeat lets the sprite react to things that change, like a key press or touching a colour.

Common mistakes: The if block must sit inside a forever loop so it is checked on every repeat. With repeat 1, the loop runs only once, so the sprite checks for the edge just one time. Line 1 should be forever. Each time the if block is true, the score should go up by 1. Setting it to 1 every time means the score never reaches 5, so the loop never ends. Line 4 should be change score by 1.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 61–74) and word search (Modules 41–74).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A Scratch script has a forever block with an if block inside it. How often is the if condition checked?
Only once, at the startEvery time the loop repeats
Matches
if touching edge? then forever turn 15 degrees
↓
The if block is outside the loop, so touching edge? is checked only once, at the start, and never again.
Applying
Meanings
Term
if inside a loop
Meaning
An if block placed inside a loop is checked again on every repeat, so the program makes a new decision each time round, like in forever or repeat until.
Practice
when green flag clicked
Testing
Gaps
Check Answer
Spots
1repeat 1
2 if touching edge? then

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Nautilus' badge — Default Expert, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A Scratch script has a forever block with an if block inside it. How often is the if condition checked?
A. Every time the loop repeats ✓
B. Only once, at the start
The if block sits inside the loop, so it is checked again on every repeat. That lets the program make a new decision each time round.
2. Which script keeps checking whether the player is touching the edge while the game runs?
A. if touching edge? then ... (with no loop around it)
B. forever { if touching edge? then ... } ✓
An if block on its own is only checked once. Put it inside a forever block and it is checked again and again.
3. Mia puts an if block BEFORE a forever block. The if checks 'key space pressed?'. What happens?
A. It keeps checking the key for the whole game
B. It only checks the key once, so it will probably miss later key presses ✓
Only blocks inside the loop are repeated. To keep watching the keyboard, the if must go inside the forever block.
4. In 'repeat until score = 10', you add an if block inside that says 'if touching apple then change score by 1'. When is the if checked?
A. On every repeat, until the score reaches 10 ✓
B. Only on the very last repeat
The if is checked each time round the loop. The loop stops when score = 10 becomes true.
5. What is the main reason to put an if block inside a loop?
A. So the program can make a new decision each time round ✓
B. So the loop runs faster
Checking the condition on every repeat lets the sprite react to things that change, like a key press or touching a colour.

Match the Pairs

forever if touching edge? then turn 180 degrees → The sprite checks the edge on every repeat, forever, and turns whenever it is touching the edge.
repeat until score = 10 if key space pressed? then change score by 1 → The loop keeps checking for the space key and adds 1 to score each time it is pressed, until score reaches 10.
An if block inside a loop is checked again on every repeat, so the program can make a new decision each time. → forever if touching color red? then say Ouch!
A repeat until loop can hold an if block, so the loop checks its own stop condition and also makes decisions inside. → repeat until lives = 0 if touching enemy? then change lives by -1
if touching edge? then forever turn 15 degrees → The if block is outside the loop, so touching edge? is checked only once, at the start, and never again.
repeat until score = 5 if touching star? then change score by 1 if touching bomb? then say Boom! → The second if block sits below the loop, so the bomb is only checked once after the loop ends, not on every repeat.

Key Term

if inside a loop
An if block placed inside a loop is checked again on every repeat, so the program makes a new decision each time round, like in forever or repeat until.

Fill in the Blanks

1. forever if <key space pressed?> then say "Jump!"
Hint: Type the name of the loop block that repeats without ever stopping.
2. forever if <touching edge?> then turn 15 degrees
Hint: Type the block that makes a decision each time the loop goes round.
3. repeat until <score = 10> if <touching coin?> then change score by 1
Hint: Type the block that checks a condition on every repeat inside the loop.
4. repeat until <score = 10> if <touching coin?> then change score by 1
Hint: Type the word that makes the loop run until its condition becomes true.
5. repeat until <lives = 0> if <touching ghost?> then change lives by -1
Hint: Type the variable name that keeps track of the player's chances.

Spot the Error

Question 1
A repeat 1
B if touching edge? then
C turn 15 degrees
D move 10 steps
Line A — The if block must sit inside a forever loop so it is checked on every repeat. With repeat 1, the loop runs only once, so the sprite checks for the edge just one time. Line 1 should be forever.
Question 2
A set score to 0
B repeat until score = 5
C if touching star? then
D set score to 1
E say You win!
Line D — Each time the if block is true, the score should go up by 1. Setting it to 1 every time means the score never reaches 5, so the loop never ends. Line 4 should be change score by 1.
Question 3
A when green flag clicked
B forever
C when touching Cat? then
D say Caught you!
Line C — Inside the forever loop we need an if block to make a decision on every repeat. 'when' is not a decision block. Line 3 should be if touching Cat? then.
Question 4
A set lives to 3
B repeat until lives > 0
C if touching Ghost? then
D change lives by -1
Line B — Lives starts at 3, so lives > 0 is true straight away and the loop stops before the if block is checked even once. It should be repeat until lives = 0.
Question 5
A set speed to 0
B forever
C if speed < 10 then
D say Too fast!
E change speed by 1
Line C — The sprite should only say 'Too fast!' when the speed is greater than 10. Using < makes it say that while it is still slow. Line 3 should be if speed > 10 then.

Student with a class code? Join your class →