Introduction to Selection: If/Else
Students learn to use basic 'if/else' statements to make decisions in their code, creating branching paths.
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
- Explain how an 'if/else' statement directs the flow of a program.
- Predict the outcome of a simple program with a single 'if/else' condition.
- 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
Why: Students need to understand how to write and execute code in a specific order before they can introduce decision-making structures.
Why: While not strictly required, prior exposure to variables helps students understand how conditions are often based on changing values.
Key Vocabulary
| if/else statement | A programming structure that checks a condition. If the condition is true, one block of code runs; otherwise, a different block of code runs. |
| condition | A statement that can be evaluated as either true or false, used to make decisions in a program. |
| program flow | The order in which instructions are executed in a program. 'If/else' statements create branching paths in this flow. |
| branching | Creating 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 activitiesUnplugged: Condition Card Sort
Provide cards with conditions, true/false outcomes, and actions. Pairs arrange them into if/else flows for scenarios like a game's win condition. Pairs then translate one flow into Scratch code and test it. Discuss variations as a class.
Pair Programming: Sprite Decisions
In Scratch, pairs code a sprite that changes costume if a variable exceeds 5 or plays sound otherwise. They add a loop for repetition. Pairs swap codes to predict and debug partner versions.
Small Groups: Game Branch Challenge
Groups modify a shared Scratch game template: use if/else for score-based messages or enemy avoidance. Test against classmates, record bugs, and refine. Present one working branch to the class.
Whole Class: Prediction Walkthrough
Display code snippets with if/else on the board or shared screen. Class votes on outcomes step-by-step, then runs in Scratch to verify. Volunteers explain flow corrections.
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
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!''
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.
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?
What are common if/else errors for KS2 pupils?
How can active learning help teach if/else selection?
What Scratch activities practice if/else for game mechanics?
More in Complex Variables and Game Mechanics
Introduction to Variables: Storing Information
Students learn the fundamental concept of variables as containers for storing different types of data within a program.
2 methodologies
Changing States with Variables
Students investigate how updating variable values can alter the state and behavior of a program or game.
2 methodologies
Sensing User Input with Variables
Students learn to use sensing blocks and variables to capture and respond to user interactions like keyboard presses or mouse clicks.
2 methodologies
Complex Scoring Systems
Students apply their understanding of variables to create sophisticated scoring mechanisms in games, including bonuses and penalties.
2 methodologies
Nested Selection and Multiple Conditions
Students explore how to use nested 'if' statements and combine conditions with 'AND' and 'OR' to create more complex decision-making logic.
2 methodologies
Debugging Strategies for Logic Errors
Students develop systematic approaches to identify and correct errors in their program's decision-making logic.
2 methodologies