Community resourceWorksheet

1CP2-CT-2.6 Understanding condition-controlled while loops

Part 6 of 8 · 1CP2-CT-2 · Selection, strings and while loops

The reading worksheet for condition-controlled loops, taken one complete pass at a time before any are written.

Students will:

  • identify the three parts every while loop needs
  • trace a loop pass by pass and state every output
  • say when a pre-condition loop executes zero times
  • diagnose a non-terminating loop and give the fixing line
  • predict the final output of a loop from its listing

Inside: 7 explanation cells, 3 multiple-choice questions, 2 fill-in-the-blanks cells and 3 written answers. 17 marks, about 45 minutes.

Series: 1CP2-CT-2 · Selection, strings and while loops, part 6 of 8.

Shared by Coding PathwayVerified teacher

  • 15 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Understanding condition-controlled while loops

A while loop repeats a block while its condition is true. It is condition-controlled: the number of repetitions may depend on changing data rather than being fixed in advance.

1. Three parts prevent guesswork

count = 1                 # initialise
while count <= 4:        # test
    print(count)
    count = count + 1    # update

The condition is checked before every pass. If it is false initially, the body runs zero times. The update moves the state toward termination.

Fill in the blanks3 marks
count = 1 is the gap 1. count <= 4 is the gap 2. count = count + 1 is the gap 3.
  • condition
  • initialisation
  • output
  • update

2. Trace one complete pass at a time

Record the value used in the body, then apply the update.

Condition before passOutputcount after update
1 <= 4 True12
2 <= 4 True23
3 <= 4 True34
4 <= 4 True45
5 <= 4 Falseno pass5

The final false check is important even though it produces no output.

Written answer4 marks

Trace value = 8; while value > 2: print(value); value = value - 2. State every output and the final value.

Apply the update after each printed value, then perform the final false check.

Students type their answer here.

Multiple choice1 mark

When does a pre-condition while loop execute zero times?

  • AWhen its condition is false at the first check
  • BWhen its update changes a variable
  • CWhen its body contains output
  • DWhen its condition eventually becomes false

3. Read the loop as a flow

A condition diamond sends True into the body. After the body and update, an arrow returns to the same condition. False leaves the loop. A return arrow without a state-changing update is a warning sign for an infinite loop.

Fill in the blanks3 marks
A gap 1 outcome enters the loop body. After the gap 2, control returns to the condition. A gap 3 outcome exits the loop.
  • False
  • True
  • input
  • update

4. Diagnose non-termination

attempts = 0
while attempts < 3:
    print("Try again")

This condition remains true because attempts never changes. The program repeatedly prints the message. This is a logic error: the syntax is valid, but the behaviour is wrong.

Written answer2 marks

Give one precise line that fixes the non-terminating loop and state where it must be indented.

Move attempts toward 3 once per pass.

Students type their answer here.

5. Predict from a code listing

Read the listing without executing it. Trace the loop before choosing its final output.

total = 0
number = 1
while number <= 3:
    total = total + number
    number = number + 1
print(total)
Multiple choice1 mark

What is the final printed output?

  • A`3`
  • B`5`
  • C`6`
  • D`7`
Written answer2 marks

Explain how total changes on each pass and why the loop stops after adding 3.

Show the running totals and the final false condition.

Students type their answer here.

Multiple choice1 mark

Which feature makes a while loop condition-controlled?

  • AIt always repeats exactly ten times.
  • BIts continuation depends on a Boolean condition checked each pass.
  • CIt can contain only one statement.
  • DIt must use the variable name count.

Route forward

You can now trace a while loop, recognise zero passes and diagnose a missing update. Next you will construct loops that meet stated requirements and test their boundaries.