Skip to content
Computing · Year 5 · Variables in Games · Spring Term

IF/ELSE Statements

Implementing branching paths in code to allow for different outcomes based on conditions.

National Curriculum Attainment TargetsKS2: Computing - Programming and Algorithms

About This Topic

IF/ELSE statements enable programs to make decisions by executing different code blocks based on whether a condition is true or false. In Year 5's Variables in Games unit, students implement branching paths, such as checking if a game score variable exceeds 10 to add a life or display a message with ELSE. This aligns with KS2 Computing standards for designing and implementing algorithms using selection, building logical reasoning from prior variable work.

The ELSE block acts as a safety net, handling all cases not caught by IF, while condition order prevents errors like misplaced checks. Students justify choices by designing quiz programs where score thresholds trigger outcomes, fostering debugging skills and precise code structure.

Active learning benefits this topic greatly because students run and tweak code live, observing how small changes alter paths. Pair debugging sessions make condition logic visible through trial and error, while unplugged sorts clarify order before coding, ensuring concepts stick through direct cause-effect experiences.

Key Questions

  1. Explain how the 'else' block provides a safety net for our program.
  2. Justify why the order of conditional checks is important in a script.
  3. Design a simple quiz program using selection with IF/ELSE statements.

Learning Objectives

  • Design a simple game scenario that uses an IF/ELSE statement to control character movement based on a condition.
  • Explain how an ELSE block provides a default action when an IF condition is false.
  • Justify the order of conditional checks in a script by predicting program behavior with different input sequences.
  • Create a short program that demonstrates branching logic for at least two different outcomes.

Before You Start

Introduction to Variables

Why: Students need to understand how to store and change data, as IF/ELSE statements often check the value of variables.

Basic Programming Concepts (Sequencing)

Why: Students must grasp that code runs in order to understand how IF/ELSE statements alter that sequence.

Key Vocabulary

IF statementA command that checks if a condition is true. If it is, a specific block of code runs.
ELSE statementA command that runs a block of code only if the preceding IF condition is false. It acts as a default path.
conditionA statement that can be evaluated as either true or false, used to control the flow of a program.
branchingThe process of a program taking different paths of execution based on whether a condition is met.

Watch Out for These Misconceptions

Common MisconceptionELSE is optional and only used for extra actions.

What to Teach Instead

ELSE ensures a response for false conditions, preventing blank outputs or errors. Hands-on testing shows programs halting without it; pair runs with varied inputs reveal the safety net's role quickly.

Common MisconceptionThe order of IF conditions never affects results.

What to Teach Instead

Specific conditions must precede general ones to avoid overlap, like checking 'score == 100' before '> 50'. Station debugging lets students input test values and see wrong paths, adjusting order collaboratively.

Common MisconceptionIF/ELSE handles only two outcomes total.

What to Teach Instead

Nested IF/ELSE or chained ELSE IF allow multiples, but basics start simple. Flowchart relays help students map branches visually before coding, clarifying expansion through group discussion.

Active Learning Ideas

See all activities

Real-World Connections

  • Video game developers use IF/ELSE statements extensively to manage player actions and game events. For example, an IF statement might check if the player presses the jump button, while an ELSE statement could handle what happens if no button is pressed.
  • Traffic light systems use conditional logic similar to IF/ELSE statements. A traffic light might turn green IF the sensor detects a car, and ELSE it might stay red or change to yellow based on a timer.

Assessment Ideas

Exit Ticket

Give students a small code snippet with an IF/ELSE statement. Ask them to write down what the output will be if the condition is true, and what the output will be if the condition is false.

Discussion Prompt

Pose this scenario: 'Imagine a program that gives a player a bonus point if they collect 10 coins. What happens if they collect 9 coins? How does the ELSE statement help ensure something still happens?'

Quick Check

Present two simple code blocks, one with the IF statement first and one with the ELSE statement first. Ask students to predict which one will run correctly and explain why the order matters for the program's logic.

Frequently Asked Questions

How to teach IF/ELSE statements in Year 5 computing?
Start unplugged with card sorts to sequence conditions, then move to block coding like Scratch for game scores. Emphasise ELSE as default and test order with inputs. Pair programming builds confidence as students explain logic aloud, meeting KS2 selection standards through practical quizzes.
Why does condition order matter in IF/ELSE code?
Order ensures precise matching; a broad check like 'score > 0' first catches specifics like 'score == 100'. Students discover this via debugging stations where swapped conditions yield wrong outputs, justifying fixes in logs for deeper understanding.
How can active learning help students master IF/ELSE?
Active approaches like live coding relays and pair debugging provide instant feedback on branch paths. Students input test values, see ELSE triggers, and reorder conditions collaboratively. This turns abstract logic into tangible trial-error cycles, far outperforming worksheets for retention and skill transfer to game design.
Ideas for quiz programs using IF/ELSE in primary computing?
Build quizzes tracking score variables: IF score >= 80 show 'Excellent!', ELSE IF >= 50 'Good try', ELSE 'Practice more'. Add nested checks for bonuses. Whole-class sharing of code variations reinforces justification of structures, aligning with unit key questions.