Skip to content
Computing · Year 6 · Complex Variables and Game Mechanics · Autumn Term

Introduction to Selection: If/Else

Students learn to use basic 'if/else' statements to make decisions in their code, creating branching paths.

National Curriculum Attainment TargetsKS2: Computing - Programming and Algorithms

About This Topic

In Year 6 Computing, aligned with the National Curriculum's KS2 requirements for using selection in programs, students meet 'if/else' statements to add decision points to their code. These structures check a condition, such as a variable value or sprite position, and execute one block of code if true or another if false. This creates branching paths essential for interactive games, like making a character jump only if a key is pressed or change direction on collision.

As part of the Complex Variables and Game Mechanics unit in Autumn Term, this topic addresses key questions on explaining program flow, predicting outcomes, and designing conditional changes. Students build computational thinking by decomposing problems into testable conditions, debugging paths, and iterating designs. It connects prior sequence work to more sophisticated algorithms, preparing for variables and repetition combinations.

Active learning suits this topic well. Students gain quick feedback by running code in block editors like Scratch, observing branches visually. Pair debugging and prediction games reveal logic flaws through trial and error, while group challenges encourage sharing condition strategies. These methods make abstract flow control concrete and boost confidence in program design.

Key Questions

  1. Explain how an 'if/else' statement directs the flow of a program.
  2. Predict the outcome of a simple program with a single 'if/else' condition.
  3. Design a program where a character changes appearance based on a simple condition.

Learning Objectives

  • Explain how an 'if/else' statement controls program execution based on a condition.
  • Predict the output of a simple program containing a single 'if/else' structure.
  • Design a short program that uses an 'if/else' statement to alter a character's behavior or appearance.
  • Compare the execution paths of two programs, one with an 'if/else' and one without, given the same input.

Before You Start

Sequencing Instructions

Why: Students need to understand how to write and execute code in a specific order before they can introduce decision-making structures.

Introduction to Variables (Optional but helpful)

Why: While not strictly required, prior exposure to variables helps students understand how conditions are often based on changing values.

Key Vocabulary

if/else statementA programming structure that checks a condition. If the condition is true, one block of code runs; otherwise, a different block of code runs.
conditionA statement that can be evaluated as either true or false, used to make decisions in a program.
program flowThe order in which instructions are executed in a program. 'If/else' statements create branching paths in this flow.
branchingCreating different paths in a program's execution based on whether a condition is met. 'If/else' statements are a form of branching.

Watch Out for These Misconceptions

Common MisconceptionThe 'else' branch runs even if the 'if' condition is true.

What to Teach Instead

Remind students that only one branch executes based on the condition's truth value. Active prediction in pairs, where they trace code paths on paper before running, helps spot this. Visual block nesting in Scratch reinforces mutual exclusivity during group debugging.

Common MisconceptionAny expression works as an 'if' condition, ignoring data types.

What to Teach Instead

Conditions must evaluate to true or false, like comparisons on numbers or strings. Unplugged sorts with mismatched cards prompt discussion. Coding and testing in small groups reveals runtime errors, guiding students to fix with proper operators.

Common MisconceptionOrder of multiple 'if/else' statements does not affect outcomes.

What to Teach Instead

Sequential evaluation means later statements check after earlier branches. Whole-class walkthroughs with predictions highlight this. Students adjust game code in pairs, observing how reordering changes behavior, building flow intuition.

Active Learning Ideas

See all activities

Real-World Connections

  • Video game developers use 'if/else' statements extensively to control character actions, enemy behavior, and game events. For example, an 'if/else' might determine if a player character jumps when the spacebar is pressed, or if an enemy attacks when the player is within range.
  • Traffic light systems use conditional logic similar to 'if/else' statements. A light might stay green for a set time, but if sensors detect cars waiting on a side street (a condition), an 'else' path could trigger the light to change sooner.

Assessment Ideas

Quick Check

Present students with a short code snippet using Scratch or a similar block-based language that includes an 'if/else' statement. Ask them to write down what the sprite will do if the condition is true, and what it will do if the condition is false. For example: 'If score > 10, say 'You win!' else say 'Keep playing!''

Exit Ticket

Give students a scenario, such as 'Design a program where a character says 'Hello!' if it is daytime, and 'Good evening!' if it is nighttime.' Ask them to write the 'if/else' condition and the two messages the character would say.

Discussion Prompt

Pose the question: 'Imagine you are designing a simple game where you collect coins. How could you use an 'if/else' statement to make the game more interesting?' Encourage students to share ideas about what might happen if they collect a certain number of coins, or if they don't collect enough.

Frequently Asked Questions

How do I introduce if/else statements in Year 6 Scratch lessons?
Start with unplugged activities like sorting condition cards into flows, linking to real decisions such as traffic lights. Move to Scratch by coding simple sprite responses, like color changes on touch. Use the sensing blocks for conditions. Build gradually to game integrations, with pair prediction before testing to solidify understanding. This sequence matches KS2 progression and keeps engagement high.
What are common if/else errors for KS2 pupils?
Pupils often forget indentation or nesting, causing whole blocks to run unexpectedly. They mix data types in conditions, leading to false results, or assume else always follows if without chains. Nested ifs confuse flow prediction. Address with visual traces and debug challenges: pairs run code step-by-step, noting where paths diverge, and correct collaboratively to prevent recurrence.
How can active learning help teach if/else selection?
Active methods like pair programming and prediction relays provide instant feedback as students run and tweak code, seeing branches activate visually in Scratch. Group challenges expose errors through peer testing, fostering explanation skills. Unplugged sorts build intuition before digital work. These approaches turn passive reading into hands-on mastery, improving prediction accuracy and debugging confidence over lectures.
What Scratch activities practice if/else for game mechanics?
Create conditional character actions, such as hiding if health is zero or speeding up if score hits 10. Add sensing for edge touches or key presses. Groups iterate on shared games, testing against rules. Include prediction sheets for outcomes. These tie to unit goals, develop decomposition, and make abstract logic tangible through playtesting and refinement.