Selection: Making Choices with 'if' (Year 5)

💻 Computer Science Year 5 Foundation

Learn how selection lets a program choose what to do, how 'if … then …' works, and how a condition can be true or false, like 'if touching the edge, turn around'.

Open this lesson, with practice and a printable worksheet →

Selection means the program makes a choice. Instead of always doing the same thing, it looks at what is happening and picks what to do next.

Why this matters: Real programs and games need to react. A character should turn when it hits a wall, or say ‘Well done’ only when you win. Selection is how a program makes smart choices instead of blindly doing the same steps every time.

The ‘if … then …’ block

The if block is shaped so other blocks fit inside it. It works like this: if something is true, then do the blocks inside. If it is not true, the inside blocks are skipped.

What is a condition?

A condition is a question the computer can answer with only true or false. For example, "Is the sprite touching the edge?" If the answer is true, the ‘if’ runs its inside blocks. If it is false, they are skipped.

ConditionAnswerRun the inside blocks?
touching the edge?trueYes
touching the edge?falseNo, skip them

A bouncing sprite

Often ‘if’ is checked again and again inside a loop, so the sprite keeps reacting. This is how a ball can bounce around the screen forever:

Put these steps in order for a bouncing sprite:

  1. Sprite moves 5 steps
  2. Check: is it touching the edge?
  3. If true, turn around
  4. Loop back and move again

The computer checks the condition every time round the loop, over and over, so the sprite keeps reacting to the edge without you doing anything more.

Get the printable worksheet →
← Loops: Making Code Repeat (Year 4–5) → Staying Safe Online (Year 3–4)
← Sasta Basta home All subjects