← ACARA Digital Technologies Years 7–8

Nested if statements

A nested if is an if inside another if's braces. The inner if is only checked when the outer condition is true. Each if has its own braces and the inner one is indented again.

Understanding Nested if statements in ACARA Digital Technologies Years 7–8

What it does: The inner if has its own { } and sits inside the outer if's { }. The extra indentation shows which block it belongs to. Checking isLoggedIn and then isAdmin inside it gives the same result as combining them with &&, so a nested if can be written as one condition. Each if needs its own pair of braces. The wrong version is missing one closing brace, so the outer block is never closed. x > 5 is false, so the inner if is never checked, even though x > 1 would be true. Both a and b must be true for the code to run. || only needs one of them.

Common mistakes: The console.log call is missing its closing bracket. It should be console.log("Teen"); with the ) before the semicolon. The comparison operator is written backwards. In JavaScript 'greater than or equal to' is >=, not =>, so the outer if should be if (score >= 50) {.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 583–598) and word search (Modules 583–613).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
When is the inner if checked in: if (age >= 13) { if (hasPermission) { ... } }
Every time the program runsOnly when age >= 13 is true
Matches
if (x > 0) { if (x < 10) { console.log("Small"); }
↓
The inner if is missing its closing brace, so the braces do not match. Each if needs its own { and }.
Applying
Meanings
Term
if (a) { if (b) { } }
Meaning
A nested if is an if inside another if's braces. The inner if is only checked when the outer condition is true. Each if has its own braces and the inner one is indented again.
Practice
let age = 14;
Testing
Gaps
(hasPass) { console.log("Enter"); }
Check Answer
Spots
3 if (age < 18) {
4 console.log("Teen";

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Red Panda' badge — Forest Explorer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. When is the inner if checked in: if (age >= 13) { if (hasPermission) { ... } }
A. Every time the program runs
B. Only when age >= 13 is true ✓
The inner if sits inside the outer if's braces, so it is skipped completely when the outer condition is false.
2. Which nested if is written correctly?
A. if (score > 50) { if (score > 90) { console.log('Top!'); } } ✓
B. if (score > 50) { if (score > 90) { console.log('Top!'); }
Each if needs its own pair of braces. The wrong version is missing one closing brace, so the outer block is never closed.
3. Is the inner if indented again in good style?
A. No, it lines up with the outer if
B. Yes, it moves in one more level to show it is inside the outer if ✓
Extra indentation makes it easy to see which block each if belongs to.
4. let x = 3; if (x > 5) { if (x > 1) { console.log('Hi'); } } What is printed?
A. Nothing ✓
B. Hi
x > 5 is false, so the inner if is never checked, even though x > 1 would be true.
5. Which && condition does the same job as: if (a) { if (b) { ... } }
A. if (a && b) { ... } ✓
B. if (a || b) { ... }
Both a and b must be true for the code to run. || only needs one of them.

Match the Pairs

if (age >= 13) { if (hasPermission) { console.log("Join"); } } → The inner if (hasPermission) is only checked when age >= 13 is true. It sits inside the outer braces and is indented again.
if (score > 50 && lives > 0) { → One if with a combined condition. Both parts must be true, and no inner if is needed.
Each if has its own braces, and the inner if is indented again inside the outer block → if (raining) { if (hasUmbrella) { console.log("Walk"); } }
A nested if is the same as one if joined with && when there is no else → if (isLoggedIn && isAdmin) { console.log("Welcome"); }
if (x > 0) { if (x < 10) { console.log("Small"); } → The inner if is missing its closing brace, so the braces do not match. Each if needs its own { and }.
if (age >= 13) { if (hasPermission === true) { console.log("Join"); } } → The console.log line is not indented again inside the inner if. Its position makes it look like it belongs to the outer if.

Key Term

if (a) { if (b) { } }
A nested if is an if inside another if's braces. The inner if is only checked when the outer condition is true. Each if has its own braces and the inner one is indented again.

Fill in the Blanks

1. if (age >= 13) { if (hasPass) { console.log("Enter"); } }
Hint: Type the keyword that starts the inner check inside the outer if's braces.
2. if (score >= 50) { if (score >= 90) { console.log("Top"); } }
Hint: Type the comparison operator that means 'greater than or equal to'.
3. if (isRaining) { if (hasUmbrella) { console.log("Go"); } }
Hint: Type the symbol that closes the inner if's own block.
4. if (age >= 13 && hasPass) { console.log("Enter"); }
Hint: Type the logical operator that requires both conditions to be true in a single if.
5. if (loggedIn) { if (role === "admin") { console.log("Hi"); } }
Hint: Type the operator that checks whether role is strictly equal to the text.

Spot the Error

Question 1
A let age = 16;
B if (age >= 13) {
C if (age < 18) {
D console.log("Teen";
E }
F }
Line D — The console.log call is missing its closing bracket. It should be console.log("Teen"); with the ) before the semicolon.
Question 2
A let score = 85;
B if (score => 50) {
C if (score >= 80) {
D console.log("Great");
E }
F }
Line B — The comparison operator is written backwards. In JavaScript 'greater than or equal to' is >=, not =>, so the outer if should be if (score >= 50) {.
Question 3
A let temp = 28;
B if (temp > 25) {
C if (temp > 35)
D console.log("Too hot");
E }
F }
Line C — The inner if has lost its opening brace. Each if needs its own braces, so it should be if (temp > 35) { to match its closing }.
Question 4
A let level = 6;
B If (level >= 5) {
C if (level >= 10) {
D console.log("Expert");
E }
F }
Line B — JavaScript is case sensitive, so the keyword must be a lowercase if. It should be if (level >= 5) {.
Question 5
A let lives == 3;
B if (lives > 0) {
C if (lives === 1) {
D console.log("Last life");
E }
F }
Line A — A variable is given its value with a single =. The == symbol is for comparing, so the line should be let lives = 3;.

Student with a class code? Join your class →