← IGCSE Computer Science Paper 2

Iterative testing while coding

Testing each small part of the code as it is written, fixing any errors, then retesting before moving on. This finds errors early and repeats until that part works.

Understanding Iterative testing while coding in IGCSE Computer Science Paper 2

What it does: Running the loop as soon as it is written shows any error straight away, while the problem is still small and easy to find. Iterative testing means testing each small part as it is written, fixing errors and retesting. After fixing an error you must retest to check that the fix worked and nothing else broke. You repeat the test and fix cycle until that part works, then move on. Both are needed. Iterative testing happens in the coding stage, and the testing stage checks the finished program. Errors found early are quicker and cheaper to fix than errors hidden in a large amount of untested code.

Common mistakes: Iterative testing means test, fix, then retest. Moving on straight after fixing skips the retest, so the fix is never checked. It should read: // Fix errors, then retest. Testing this part gives 3 instead of the expected 6, which shows an error. Total is overwritten each time instead of being added to. The fix is Total ← Total + Count, then retest.

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 1–16) and word search (Modules 1–26).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A student writes one subroutine, runs it with some test values, fixes a mistake, then runs it again. What is this called?
Iterative testingWriting the whole program first and testing it only at the end
Matches
Write the whole program, then test it only once at the end
↓
This leaves all testing to the end, so errors are found late and are harder to locate. Iterative testing tests each small part as it is written.
Applying
Meanings
Term
Iterative testing
Meaning
Testing each small part of the code as it is written, fixing any errors, then retesting before moving on. This finds errors early and repeats until that part works.
Practice
// Part 1: add two marks
Testing
Gaps
PartWorks = TRUE
Check Answer
Spots
2// Test that part now
3// Fix errors, then move on

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

The 'African Wild Dog' badge — Savannah Streak, 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. A student writes one subroutine, runs it with some test values, fixes a mistake, then runs it again. What is this called?
A. Writing the whole program first and testing it only at the end
B. Iterative testing ✓
Iterative testing means testing each small part as it is written, fixing errors and retesting.
2. What is the correct order in iterative testing?
A. Test, fix, retest ✓
B. Fix, write more code, test once at the end
After fixing an error you must retest to check that the fix worked and nothing else broke.
3. When do you move on to the next part of the program?
A. When the current part passes its tests ✓
B. As soon as you have finished typing the current part
You repeat the test and fix cycle until that part works, then move on.
4. Why does iterative testing find errors early?
A. Errors cannot happen if the code is tested at the end
B. Each small part is tested straight after it is written, so a fault is easy to locate ✓
Testing small parts means that if a test fails, the error must be in the code you just wrote.
5. A student fixes an error in a loop and then moves straight on without running it again. Is this iterative testing?
A. No, the fix has not been retested ✓
B. Yes, fixing the error is enough
Iterative testing needs a retest after every fix. The fix might not work or might cause a new error.

Match the Pairs

Iterative testing → Testing each small part of the code as it is written, fixing any errors, then retesting before moving on
Test, fix, retest → The repeating cycle used on one part of the code until that part works correctly
Iterative testing finds errors early because each new part of the code is tested straight after it is written → Write the FOR loop, run it, find the error now
Repeat until the part works: after a fix, the same part is tested again before moving on → REPEAT Test the part Fix any errors UNTIL Part works
Write the whole program, then test it only once at the end → This leaves all testing to the end, so errors are found late and are harder to locate. Iterative testing tests each small part as it is written.
Find an error, fix it, then move straight on to the next part → The fix is never retested, so the programmer cannot be sure the part now works or that the fix did not add a new error. The part must be tested again before moving on.

Key Term

Iterative testing
Testing each small part of the code as it is written, fixing any errors, then retesting before moving on. This finds errors early and repeats until that part works.

Fill in the Blanks

1. REPEAT // test the part, then fix any errors UNTIL PartWorks = TRUE
Hint: Type the keyword that ends a REPEAT loop and gives the condition for stopping.
2. WHILE PartWorks = FALSE DO // fix the error and retest ENDWHILE
Hint: Type the BOOLEAN value that means the part still has errors, so the loop keeps going.
3. IF ActualOutput = ExpectedOutput THEN PartWorks ← TRUE ENDIF
Hint: Type the keyword that follows the condition when the test result matches what was expected.
4. DECLARE Retests : INTEGER Retests ← 0 Retests ← Retests + 1
Hint: Type the arithmetic operator that adds one to the count each time the part is tested again.
5. IF ErrorsFound > 0 THEN // fix the error, then retest ENDIF
Hint: Type the relational operator that checks whether at least one error was found in the test.

Spot the Error

Question 1
A // Write one small part
B // Test that part now
C // Fix errors, then move on
D // Move on when it works
Line C — Iterative testing means test, fix, then retest. Moving on straight after fixing skips the retest, so the fix is never checked. It should read: // Fix errors, then retest.
Question 2
A Total ← 0
B FOR Count ← 1 TO 3
C Total ← Count
D NEXT Count
E OUTPUT Total
Line C — Testing this part gives 3 instead of the expected 6, which shows an error. Total is overwritten each time instead of being added to. The fix is Total ← Total + Count, then retest.
Question 3
A // Test only when all is done
B // Fix any errors found
C // Retest the part
D // Then write the next part
Line A — Iterative testing tests each small part as it is written, not only at the end. Waiting lets errors build up and makes them harder to find. It should read: // Test each part as written.
Question 4
A INPUT Age
B WHILE Age < 0 AND Age > 120 DO
C OUTPUT "Invalid age"
D INPUT Age
E ENDWHILE
Line B — Testing with -5 shows the loop never runs. No number is both below 0 and above 120, so AND is never true. The condition needs OR, then the part is retested.
Question 5
A // Test 1: Total of 5 and 7
B // Expected output: 35
C Total ← 5 + 7
D OUTPUT Total
Line B — A test needs the correct expected output, or the result can't be judged. 5 + 7 gives 12, not 35, so the expected output should be 12.

Student with a class code? Join your class →