← ACARA Digital Technologies Years 9–10

A WHILE loop with a compound condition

The loop repeats only while BOTH tests are TRUE. As soon as either test becomes FALSE, the whole condition is FALSE and the loop stops.

Understanding A WHILE loop with a compound condition in ACARA Digital Technologies Years 9–10

What it does: The condition is TRUE only while both tests are TRUE. A third attempt or a correct answer makes one test FALSE, which ends the loop. The index has gone past the end of the list. Index <= 10 is FALSE, so the AND condition fails even though the item was never found. The search must keep going while the item is NOT found, so Found needs NOT in front of it.

Common mistakes: The loop should continue only while BOTH tests are TRUE. With OR, it keeps going if either test is TRUE. If the item is never found, NOT Found stays TRUE, so the loop never stops. It should be AND. Lives must start above 0. If Lives starts at 0, Lives > 0 is FALSE straight away, so the whole AND condition is FALSE and the loop never runs. It should be Lives ← 3.

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 492–534) and word search (Modules 459–534).

Take this worksheet further — free with Cloodit

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

Learning
Duo
WHILE Attempts < 3 AND Correct = FALSE DO. Attempts is 1 and Correct is FALSE. What happens?
The loop repeats, because both tests are TRUEThe loop stops, because Correct is FALSE
Matches
WHILE Attempts < 3 AND Correct = TRUE DO
↓
Correct = TRUE is the wrong test. The loop would stop at once because Correct starts as FALSE. It should be Correct = FALSE so the loop continues until the answer is right.
Applying
Meanings
Term
WHILE Attempts < 3 AND Correct = FALSE DO
Meaning
The loop repeats only while BOTH tests are TRUE. As soon as either test becomes FALSE, the whole condition is FALSE and the loop stops.
Practice
Attempts ← 0
Testing
Gaps
WHILE Attempts < 3 Correct = FALSE DO
Check Answer
Spots
2I ← 1
3WHILE NOT Found OR I <= 10 DO

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

The 'Meerkat' badge — Communicator, 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. WHILE Attempts < 3 AND Correct = FALSE DO. Attempts is 1 and Correct is FALSE. What happens?
A. The loop stops, because Correct is FALSE
B. The loop repeats, because both tests are TRUE ✓
AND needs BOTH tests to be TRUE. Attempts < 3 is TRUE and Correct = FALSE is TRUE, so the loop keeps going.
2. WHILE Attempts < 3 AND Correct = FALSE DO. Attempts is 2 and Correct has just become TRUE. What happens?
A. The loop repeats, because Attempts < 3 is still TRUE
B. The loop stops, because Correct = FALSE is now FALSE ✓
With AND, one FALSE test makes the whole condition FALSE. Correct = FALSE is now FALSE, so the loop ends.
3. WHILE Attempts < 3 AND Correct = FALSE DO. Attempts is 3 and Correct is still FALSE. What happens?
A. The loop stops, because Attempts < 3 is FALSE ✓
B. The loop repeats, because Correct = FALSE is TRUE
Attempts < 3 is FALSE when Attempts is 3. One FALSE part makes the AND condition FALSE, so the loop stops.
4. A WHILE loop uses AND to join two tests. When does the loop keep repeating?
A. Only while both tests are TRUE ✓
B. While at least one test is TRUE
Continuing while at least one test is TRUE describes OR. AND needs every test to stay TRUE.
5. WHILE NOT Found AND Index <= 10 DO. Found is FALSE and Index is 4. What happens?
A. The loop repeats, because NOT Found is TRUE and Index <= 10 is TRUE ✓
B. The loop stops, because Found is FALSE
NOT Found flips FALSE into TRUE. Both parts are TRUE, so the loop continues searching.

Match the Pairs

WHILE Attempts < 3 AND Correct = FALSE DO → Keep looping only while the student has had fewer than 3 attempts and has not yet got the answer right.
WHILE NOT Found AND Index <= 10 DO → Keep searching while the item has not been found and the index has not gone past 10.
The loop stops as soon as either part of an AND condition becomes FALSE, so a password game ends after 3 tries or a correct guess. → WHILE Attempts < 3 AND Correct = FALSE DO
A search loop should continue only while the item is still not found and there are still places left to check. → WHILE NOT Found AND Index <= 10 DO
WHILE Attempts < 3 AND Correct = TRUE DO → Correct = TRUE is the wrong test. The loop would stop at once because Correct starts as FALSE. It should be Correct = FALSE so the loop continues until the answer is right.
WHILE Found AND Index <= 10 DO → Found starts as FALSE, so the condition is FALSE straight away and the loop never runs. It should be NOT Found so the search continues until the item is found.

Key Term

WHILE Attempts < 3 AND Correct = FALSE DO
The loop repeats only while BOTH tests are TRUE. As soon as either test becomes FALSE, the whole condition is FALSE and the loop stops.

Fill in the Blanks

1. WHILE Attempts < 3 AND Correct = FALSE DO
Hint: Type the logical operator that keeps the loop going only while both tests are TRUE.
2. WHILE NOT Found AND Index <= 10 DO
Hint: Type the logical operator that flips Found so the loop runs while the item has not been found.
3. WHILE Attempts < 3 AND Correct = FALSE DO
Hint: Type the relational operator that means fewer than the attempt limit.
4. WHILE NOT Found AND Index <= 10 DO Index ← Index + 1 ENDWHILE
Hint: Type the keyword that closes the WHILE loop.
5. WHILE Attempts < 3 AND Correct = FALSE DO Attempts ← Attempts + 1 ENDWHILE
Hint: Type the variable that must change each time round so the first test can eventually become FALSE.

Spot the Error

Question 1
A Found ← FALSE
B I ← 1
C WHILE NOT Found OR I <= 10 DO
D Found ← Check(I)
E I ← I + 1
F ENDWHILE
Line C — The loop should continue only while BOTH tests are TRUE. With OR, it keeps going if either test is TRUE. If the item is never found, NOT Found stays TRUE, so the loop never stops. It should be AND.
Question 2
A Lives ← 0
B Pts ← 0
C WHILE Lives > 0 AND Pts < 9 DO
D Lives ← Lives - 1
E Pts ← Pts + 2
F ENDWHILE
Line A — Lives must start above 0. If Lives starts at 0, Lives > 0 is FALSE straight away, so the whole AND condition is FALSE and the loop never runs. It should be Lives ← 3.
Question 3
A Tries ← 0
B Ok ← FALSE
C WHILE Tries < 3 AND Ok DO
D Ok ← CheckPin()
E Tries ← Tries + 1
F ENDWHILE
Line C — Ok starts as FALSE, so the second test is FALSE and the AND condition is FALSE at once. The loop should continue while the answer is NOT yet correct, so it needs NOT Ok.
Question 4
A Sum ← 100
B N ← 0
C WHILE Sum < 100 AND N < 5 DO
D Sum ← Sum + Next()
E N ← N + 1
F ENDWHILE
Line A — Sum must start at 0. If it starts at 100, Sum < 100 is FALSE straight away, so the AND condition is FALSE and the loop body never runs. It should be Sum ← 0.
Question 5
A Fuel ← 10
B Km ← 0
C WHILE Fuel > 0 AND Km < 50
D Fuel ← Fuel - 1
E Km ← Km + 8
F ENDWHILE
Line C — The WHILE line is missing the keyword DO at the end. It should be WHILE Fuel > 0 AND Km < 50 DO.

Student with a class code? Join your class →