AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    Programming concepts: WHILE NotSolved … Instructions here … ENDWHILE

    A WHILE loop repeats the instructions between WHILE and ENDWHILE while its condition stays true.

    Checked against the AQA 8525 specification (opens in a new tab) on .

    • Point 13 of 23

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    A WHILE loop repeats the instructions between WHILE and ENDWHILE while its condition stays true. Here the condition is NotSolved, so the body runs only while the flag NotSolved is true; once NotSolved becomes false the loop stops and control passes to the line after ENDWHILE. The loop is therefore condition-controlled and pre-tested: the condition is checked before each pass, so if NotSolved is already false the body never runs. The body must change something that affects the condition, for example setting NotSolved to false when the puzzle is solved, otherwise the loop never ends. Contrast this with a REPEAT…UNTIL loop, which tests after the body and so always runs at least once. When answering, trace the flag value at each check rather than guessing how many passes occur.

    What earns the marks

    • Identifies the loop as condition-controlled (a WHILE loop) rather than count-controlled.
    • States that the condition is tested before each iteration, so the body may run zero times.
    • Explains that the body repeats while NotSolved is true and stops when NotSolved becomes false.
    • Recognises that the body must update the variable controlling the condition to avoid an infinite loop.
    • Distinguishes pre-tested WHILE from post-tested REPEAT…UNTIL, which always executes the body at least once.

    Common mistakes and how to put them right

    • Assuming the body always runs at least once.

      Put it right: Is that a pre-tested WHILE checks the condition first, so it can run zero times.

    • Thinking ENDWHILE is where the condition is tested.

      Put it right: Is that the condition sits on the WHILE line and is re-evaluated each time control returns to it.

    • Believing the loop stops when NotSolved becomes true.

      Put it right: Is that it continues while NotSolved is true and stops when it becomes false.

    Exam tips

    • Trace the value of NotSolved at each check and write the pass number beside it.
    • State explicitly whether the body can run zero times and why.
    • Name the statement that changes the flag inside the body, since without it the loop is infinite.

    Try the lesson

    The start of the Programming concepts: WHILE NotSolved … Instructions here … ENDWHILE lesson, made from checked teaching notes for this specification point.

    Have a go first

    A program uses the loop WHILE NotSolved … Instructions here … ENDWHILE. What must be true for the instructions inside the loop to run at all?

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Test your understanding of Programming concepts: WHILE NotSolved … Instructions here … ENDWHILE

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge