Skip to content
Technologies · Year 7 · Coding with Purpose · Term 2

Conditional Statements: If/Else

Students write code using 'if', 'else if', and 'else' statements to control program flow based on conditions.

ACARA Content DescriptionsAC9TDI8P03

About This Topic

Control structures are the 'logic gates' of programming, allowing code to move beyond a simple top-to-bottom sequence. In Year 7, students focus on two main types: conditionals (if-then-else statements) and loops (for and while iterations). These structures enable programs to respond to user input and perform repetitive tasks efficiently, which is a core requirement of AC9TDI8P03.

By using control structures, students can create interactive games, automated systems, and smart tools. For example, a game might use a conditional to check if a player's score is high enough to level up, or a loop to generate a row of obstacles. Students grasp these concepts faster through structured discussion and peer explanation, where they predict the outcome of 'nested' logic before running the code.

Key Questions

  1. Design a program that makes decisions based on user input.
  2. Differentiate between single 'if' statements and 'if-else' structures.
  3. Predict the execution path of a program with multiple conditional branches.

Learning Objectives

  • Design a simple program that uses 'if-else' statements to respond to different user inputs.
  • Compare the execution paths of a program using only 'if' statements versus one using 'if-else if-else' structures.
  • Predict the output of a program containing multiple conditional branches based on given input values.
  • Analyze a given code snippet and identify the conditions that trigger specific code blocks.
  • Create a flowchart to represent the logic of a program incorporating conditional statements.

Before You Start

Introduction to Programming Concepts

Why: Students need a basic understanding of what code is and how it generally executes sequentially before learning control flow.

Variables and Data Types

Why: Conditional statements often check the values stored in variables, so students must be familiar with how to declare, assign, and use variables.

Comparison Operators

Why: Conditional statements rely on comparing values (e.g., greater than, less than, equal to), so students must understand these operators.

Key Vocabulary

Conditional StatementA programming structure that executes different code blocks based on whether a specified condition is true or false.
If StatementExecutes a block of code only if its associated condition evaluates to true. If the condition is false, the block is skipped.
Else If StatementChecks an additional condition if the preceding 'if' or 'else if' conditions were false. It executes its code block if its own condition is true.
Else StatementExecutes a block of code if all preceding 'if' and 'else if' conditions in the structure were false.
Boolean ExpressionAn expression that evaluates to either true or false, used as the condition in conditional statements.

Watch Out for These Misconceptions

Common MisconceptionA loop will run forever once it starts.

What to Teach Instead

Loops need a 'termination condition' to stop. Physical simulations where students have to check a condition (e.g., 'Is the bucket full?') before repeating an action help them understand how loops exit.

Common MisconceptionAn 'If' statement and a 'While' loop are the same thing.

What to Teach Instead

An 'If' statement checks a condition once, while a 'While' loop checks it repeatedly. Using a 'Logic Maze' activity helps students feel the difference between a single decision and a repeated action.

Active Learning Ideas

See all activities

Real-World Connections

  • Video game developers use conditional statements extensively to control character actions, enemy behavior, and game progression based on player input and game state. For example, an 'if' statement might check if a player has enough health points to cast a spell.
  • Traffic light control systems use conditional logic to manage traffic flow. 'If' a car is detected at an intersection and the light is red, then the light remains red; 'else if' a car is detected and the light is green, then the light stays green for a set duration.

Assessment Ideas

Exit Ticket

Provide students with a simple scenario, such as a basic temperature checker. Ask them to write pseudocode for a program that prints 'It's cold' if the temperature is below 10 degrees Celsius, and 'It's warm' otherwise. Specify they must use an 'if-else' structure.

Quick Check

Display a short code snippet with 'if', 'else if', and 'else' statements. Ask students to predict the output for two different input values. For example, 'What will this code print if the user enters 7?' and 'What will it print if the user enters 25?'

Discussion Prompt

Pose the question: 'When would you choose to use a series of separate 'if' statements instead of an 'if-else if-else' chain? Provide a brief example scenario to illustrate your point.'

Frequently Asked Questions

What is a 'nested' control structure?
A nested structure is when one control structure is placed inside another. For example, an 'if' statement inside a 'for' loop. This allows for more complex logic, such as checking a condition every time a repetitive task is performed. It is a key skill for Year 7 students to master as their programs become more sophisticated.
How can active learning help students understand control structures?
Control structures can be confusing when viewed only as text. Active learning strategies like 'Logic Mazes' or 'Predict the Output' challenges force students to step through the logic manually. This physical or social processing helps them visualize the flow of execution, making it much easier to debug their own code later.
When should a student use a 'While' loop instead of a 'For' loop?
A 'For' loop is best when you know exactly how many times you want to repeat something (e.g., 10 times). A 'While' loop is better when you want to repeat something until a certain condition changes (e.g., until the user hits the 'stop' button), even if you don't know how long that will take.
How do control structures relate to the ACARA curriculum?
ACARA standard AC9TDI8P03 requires students to implement digital solutions that include branching and iteration. Control structures are the technical tools used to achieve this. Mastery of these structures is essential for students to move from basic sequencing to creating responsive, intelligent digital systems.