AQA A-Level Computer Science AS Paper 1, June 2025: Question 2

2 marks · Easy difficulty · Short Answer

Explain why two pseudo-code blocks, one using a WHILE loop and the other using a REPEAT UNTIL loop, operate differently when the inputs are negative numbers.

Practise this question

Question

Question 02 presents two pseudo-code blocks. Figure 3 shows: INPUT X, WHILE X > 0, X <- X - 1, ENDWHILE. Figure 4 shows: INPUT X, REPEAT, X <- X - 1, UNTIL X <= 0. The question asks to explain why the pseudo-code in Figure 3 operates differently to the pseudo-code in Figure 4 when the inputs are negative numbers, worth 2 marks.
Question text

02 Figure 3 and Figure 4 show two blocks of pseudo-code.

Figure 3

INPUT X

WHILE X > 0

X ← X – 1

ENDWHILE

Figure 4

INPUT X

REPEAT

X ← X – 1

UNTIL X ≤ 0

Explain why the pseudo-code in Figure 3 operates differently to the pseudo-code in

Figure 4 when the inputs are negative numbers.

[2 marks]

Mark scheme

Show the mark scheme Mark scheme for Question 02: 2 marks for AO1 (understanding). Award up to 2 marks from: (Code within) WHILE/Figure 3 loop structure is not executed // final value of X remains the same; (Code within) REPEAT/Figure 4 loop structure will be executed (once) // the value of X changes/decreases; The WHILE loop tests the condition at the start of the loop whereas the REPEAT loop tests the condition at the end of the loop. Maximum 2 marks.

02 2 marks for AO1 (understanding) 2

(Code within) WHILE/Figure 3 loop structure is not executed // final value of X remains

the same;

(Code within) REPEAT/Figure 4 loop structure will be executed (once) // the value of X

changes/decreases;

The WHILE loop tests the condition at the start of the loop whereas the REPEAT loop

tests the condition at the end of the loop;

Max 2

How to answer it

Comparing Pre-Condition and Post-Condition Loops

📌 What this question tests

This question assesses your understanding of iteration constructs (AO1 - Knowledge and Understanding). Specifically, it evaluates whether you understand the fundamental behavioural difference between a pre-condition loop ( WHILE...ENDWHILE ) and a post-condition loop ( REPEAT...UNTIL ) when provided with boundary and invalid data (negative numbers).

Question 02 • [2 marks]

Analysis of Figure 3 (WHILE) vs Figure 4 (REPEAT...UNTIL)

Explaining differing behaviour with negative integer inputs

Figure 3: Pre-condition Loop

INPUT X WHILE X > 0 X ← X - 1 ENDWHILE

Figure 4: Post-condition Loop

INPUT X REPEAT X ← X - 1 UNTIL X ≤ 0

💡 Key Knowledge

  • Pre-condition Loop ( WHILE ): The boolean condition is evaluated before entering the loop body. If the condition evaluates to False initially, the loop body executes 0 times.
  • Post-condition Loop ( REPEAT...UNTIL ): The body executes first, and the condition is evaluated at the end. Therefore, the loop body always executes at least once.
  • Loop Termination Condition: A REPEAT...UNTIL loop terminates when the condition becomes True .

📐 Step-by-Step Trace (Input: X = -3)

  1. Figure 3:
    • Initial check: -3 > 0 evaluates to False.
    • Loop body is skipped completely.
    • Result: X remains -3 (0 iterations).
  2. Figure 4:
    • Body executes: X ← -3 - 1 (so X = -4 ).
    • Condition test: -4 ≤ 0 evaluates to True.
    • Loop terminates immediately after 1 iteration.
    • Result: X becomes -4 (decreased by 1).

✅ Acceptable Points (Any 2 for Full Marks)

  • The code inside the WHILE loop (Figure 3) is not executed / the final value of X remains unchanged. [1 mark]
  • The code inside the REPEAT loop (Figure 4) will be executed (once) / the value of X decreases / changes. [1 mark]
  • The WHILE loop tests the condition at the start of the loop, whereas the REPEAT loop tests the condition at the end of the loop. [1 mark]

🧠 Exam Technique

  • State the difference for both loops: Always explicitly reference both Figure 3 and Figure 4 (or both loop keywords) rather than giving an open-ended statement.
  • Focus on execution count or condition timing: You can either explain when the condition is checked (start vs end) or what happens to the data/loop body (0 times vs 1 time / unchanged vs decremented).

❌ Common Errors & Misconceptions

  • Stating that Figure 4 enters an infinite loop: Some students incorrectly assume that because X is negative, subtracting 1 will cause an infinite loop. However, the exit condition is X ≤ 0 , which is immediately satisfied after the first decrement.
  • Vague comparisons: Writing "one checks first and the other checks later" without identifying which figure does which loses easy marks. Always pair the name/figure with its behaviour.
  • Forgetting to address negative inputs: The question specifically asked about behaviour when inputs are negative. Explanations must clearly relate to what happens under this specific condition.
Mark Scheme Summary: Max 2 marks for AO1. 1 mark per valid distinction regarding loop execution (0 executions vs 1 execution), state of variable X (unchanged vs decremented), or location of test condition (start vs end).

Topics

4.1 Fundamentals of programming · 4.1.1 Programming

Question and mark scheme from the AQA A-Level Computer Science examination, AS Paper 1, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.