Selection: Making Decisions (If/Else)
Implementing conditional statements (if-then-else) to allow programs to make decisions based on conditions.
About This Topic
Selection with if-else statements lets programs make decisions based on true or false conditions, a key part of computational thinking. Year 7 students use Scratch to add if-then-else blocks, for example, making a sprite jump if it touches a colour or stop if a score reaches ten. Clear conditions like 'touching edge?' or 'key space pressed?' guide program flow and prevent unexpected behaviour.
This topic aligns with KS3 Computing standards in programming and development, within the Autumn unit on computational thinking and logic. Students explain how selection controls outcomes, construct responsive scripts, and evaluate condition clarity to debug effectively. It connects logic to real-world decisions, like traffic lights or games.
Active learning suits this topic well. Students test code live in Scratch, see results instantly, and adjust conditions through trial and error. Collaborative challenges build confidence as peers share fixes, turning logic errors into shared discoveries.
Key Questions
- Explain how selection allows a program to make decisions.
- Construct a Scratch script that uses an 'if-else' block to control sprite behavior.
- Evaluate the importance of clear conditions in selection statements.
Learning Objectives
- Construct a Scratch program that uses an if-else statement to control sprite actions based on a specific condition.
- Explain how a true or false condition within an if-else block directs program flow.
- Evaluate the clarity and effectiveness of conditions used in selection statements to predict program behavior.
- Modify an existing Scratch script to implement a new decision-making process using if-else logic.
Before You Start
Why: Students need to understand how to arrange instructions in a specific order before they can learn to control that order with conditions.
Why: Understanding how programs react to events like 'when green flag clicked' or 'when key pressed' is foundational for setting up conditions.
Key Vocabulary
| Selection | A programming construct that allows a program to execute different blocks of code based on whether a condition is true or false. |
| Conditional Statement | A statement in programming that performs different computations or actions depending on whether a programmer-defined boolean condition evaluates to true or false. |
| If-Else Statement | A control flow statement that executes one block of code if a specified condition is true, and another block of code if the condition is false. |
| Condition | A logical expression that evaluates to either true or false, used to determine which path of execution a program should take. |
Watch Out for These Misconceptions
Common MisconceptionIf-else always runs both branches.
What to Teach Instead
Programs check the condition once; only one branch executes. Use think-pair-share where students predict outcomes for given code, then run it in Scratch to compare predictions and correct mental models through evidence.
Common MisconceptionAny text in the condition works.
What to Teach Instead
Conditions must evaluate to true or false, using operators like equals or greater than. Hands-on debugging stations let students fix broken conditions collaboratively, revealing why vague inputs fail and building precise testing habits.
Common MisconceptionNesting if-else makes code too complex.
What to Teach Instead
Simple nests handle multiple decisions, like if-then-else if-else. Group code reviews show students how nests organise logic without confusion, as they trace paths together on paper before coding.
Active Learning Ideas
See all activitiesPair Programming: Sprite Decisions
Pairs open Scratch and create a sprite that changes costume if touching the edge, else moves forward. Add a second condition for key presses to play sounds. Pairs swap roles every 10 minutes and test each other's code.
Small Groups: Game Condition Challenges
Groups receive prompt cards with scenarios like 'if score > 5, speed up else slow down.' They build and demo one script per card in Scratch. Groups vote on the clearest condition and suggest improvements.
Individual: Personal Choice Story
Each student builds a Scratch story where if-else directs paths based on clicks, like 'if choose left, show forest else show city.' Test paths and add nested conditions for branches.
Whole Class: Condition Relay
Project a base Scratch project. Students take turns adding one if-else condition shouted out by the class, like 'if y position < 0, bounce.' Run after each addition to check logic.
Real-World Connections
- Traffic light systems use conditional logic. If the sensor detects a car waiting, and the light is red, it remains red; otherwise, it might change to green after a set time, managing traffic flow in urban areas.
- Video game developers use if-else statements extensively. For example, if a player presses the 'jump' button and the character is on the ground, the character jumps; else, it remains still.
Assessment Ideas
Present students with a simple Scratch script snippet containing an if-else block. Ask them to predict what the sprite will do if a specific condition is met (e.g., 'What happens if the sprite touches the blue color?').
Ask students to write down one example of a condition they could use in a Scratch game to make a sprite react differently. Then, have them describe what the sprite should do if the condition is true and what it should do if it is false.
Pose the question: 'Why is it important for the condition in an if-else statement to be very clear and specific?' Facilitate a brief class discussion, guiding students to consider how vague conditions can lead to unexpected program behavior.
Frequently Asked Questions
How do I teach if-else statements in Scratch for Year 7?
What are common errors in if-else conditions?
How can active learning improve understanding of if-else in programming?
What extensions for advanced Year 7 if-else skills?
More in Computational Thinking and Logic
Efficiency and Optimisation
Exploring how to evaluate algorithms for efficiency and identify opportunities for optimisation.
2 methodologies
Logic Gates: AND, OR, NOT
Introduction to fundamental logic gates and their truth tables as building blocks of digital circuits.
2 methodologies
Boolean Logic and Expressions
Understanding Boolean operators and writing simple Boolean expressions to represent conditions.
2 methodologies
Introduction to Block Programming (Scratch)
Students will be introduced to the Scratch interface and basic block programming concepts.
2 methodologies
Sequence: Order of Instructions
Mastering the order of execution and using repetition to make code more efficient.
2 methodologies
Loops: Repetition and Efficiency
Understanding and implementing different types of loops (repeat, forever) to create efficient and concise code.
2 methodologies