Simple Conditional Logic: If/Else
Students will explore basic conditional statements (if/else) to make programs respond differently based on simple conditions.
About This Topic
Simple conditional logic with if/else statements teaches students how programs can make decisions based on conditions. At Foundation level, children use block-based tools like ScratchJr to snap together if/else blocks, creating characters that respond differently, such as playing a sound if touching a red object or moving left if on a blue background. This builds on sequencing from earlier units and aligns with AC9TDEFP01, where students create and debug simple digital solutions to share ideas.
These concepts foster computational thinking by introducing branching paths in algorithms. Students predict outcomes, test conditions like position or color, and adjust code when results differ from expectations. Connections to everyday decisions, like choosing clothes based on weather, make the idea relatable and reinforce logical reasoning across the Technologies curriculum.
Active learning shines here because students immediately see cause-and-effect through running and tweaking their programs. Pair programming encourages explanation of choices, while whole-class demos reveal diverse solutions, helping everyone grasp that conditions create flexible, responsive code.
Key Questions
- Explain how an 'if' statement allows a program to make a decision.
- Design a program where a character changes behavior based on a condition (e.g., touching an object).
- Predict the path a program will take given a specific condition.
Learning Objectives
- Explain how an 'if' statement directs a program to make a choice based on a specific condition.
- Design a simple program using ScratchJr where a character's action changes when a condition is met, such as touching a specific color.
- Predict the sequence of events in a block-based program given a set of 'if/else' conditions.
- Modify a program to alter the outcome of an 'if/else' statement by changing the condition.
- Identify the condition within an 'if/else' block that triggers a specific program response.
Before You Start
Why: Students need to understand how to order instructions for a program to run correctly before introducing conditional logic.
Why: Familiarity with the interface and basic command blocks in tools like ScratchJr is necessary to build upon.
Key Vocabulary
| Condition | A specific situation or requirement that must be true for something else to happen in a program. |
| If Statement | A block of code that tells the program to do something only if a certain condition is met. |
| Else Statement | A block of code that tells the program to do something different if the 'if' condition is not met. |
| Program Decision | When a program chooses between different paths or actions based on whether a condition is true or false. |
| Block-Based Coding | A way of creating programs by snapping together visual blocks that represent commands and logic. |
Watch Out for These Misconceptions
Common MisconceptionThe program always runs both if and else blocks.
What to Teach Instead
If/else creates branches: only one path executes based on the condition. Students test by changing inputs and observing single outcomes, which clarifies flow during pair debugging sessions.
Common MisconceptionConditions are fixed and never change.
What to Teach Instead
Conditions depend on runtime states like position or color. Hands-on dragging of sprites shows varying results, helping students predict and verify dynamic behavior in group shares.
Common MisconceptionIf block works alone without else.
What to Teach Instead
Without else, no action occurs if condition is false, leading to 'stuck' programs. Building complete if/else chains and testing edge cases in activities reveals the need for both paths.
Active Learning Ideas
See all activitiesPair Coding: Conditional Dance
Pairs select sprites and backgrounds. They add if/else blocks so the sprite dances differently if touching a music note (play sound) versus a stop sign (freeze). Test by dragging sprites and swap roles to debug.
Small Groups: Object Collector
Groups build a game where a character collects stars: if touching star, grow bigger and cheer; else, say 'keep looking'. Include obstacles that trigger warnings. Groups demo and vote on best features.
Whole Class: Prediction Challenge
Project a simple if/else program. Class predicts sprite actions for different starting positions. Run code, discuss matches, then pairs recreate and modify it.
Individual: Weather Responder
Each student codes an avatar that changes costume or message based on 'sunny' or 'rainy' backgrounds using if/else. Share one screen-wide.
Real-World Connections
- Traffic lights use 'if/else' logic: if the light is red, cars stop; else (if it is green), cars go. This ensures safe and orderly movement of vehicles.
- Video game characters often react to player input or game events using conditional logic. For example, if the player presses the jump button, the character jumps; else, the character stands still.
- Smart home devices use conditions to automate tasks. If the temperature drops below a certain point, the thermostat turns on the heating.
Assessment Ideas
Give students a simple ScratchJr project with an 'if/else' block. Ask them to draw what the character will do. Then, ask them to write one sentence explaining why the character will do that specific action.
Present students with two scenarios: 1. A character touches a blue square. 2. A character does not touch a blue square. Ask them to choose the correct block sequence for each scenario: 'If touching blue, say hello' or 'If not touching blue, say hello'.
Ask students: 'Imagine you are designing a game where a character needs to collect coins. How could you use an 'if' statement to make the character get a point only when it touches a coin?' Listen for their use of 'if', 'touching', and 'score'.
Frequently Asked Questions
How do I introduce if/else to Foundation students?
What block-based tools suit Foundation if/else?
How can active learning help teach if/else?
What if students' programs don't branch correctly?
More in Patterns and Sequences
Recognizing Simple Patterns
Students will identify and describe simple repeating patterns in various contexts (e.g., colors, shapes, sounds).
2 methodologies
Following Step-by-Step Instructions
Students will practice following and giving clear, sequential instructions for simple tasks, both unplugged and with basic digital tools.
2 methodologies
Creating Simple Sequences
Students will design and implement short sequences of actions or commands to achieve a specific outcome, using block-based coding or physical activities.
2 methodologies
Pattern Recognition in Data and Problem Solving
Applying pattern recognition techniques to analyze data, identify trends, and abstract commonalities in problem-solving contexts.
3 methodologies
Sequencing in Programming Constructs
Applying sequencing to programming constructs, understanding the order of operations, and designing step-by-step solutions for computational tasks.
3 methodologies
Introducing Loops: Repeating Actions
Students will learn about loops as a way to repeat actions efficiently in programming, using simple block-based examples.
2 methodologies