Iteration (FOR and WHILE loops)

    AQA
    GCSE

    Iteration is the algorithmic construct enabling the repetition of code blocks, fundamental to flow control and program efficiency. Candidates must distinguish between definite (count-controlled/FOR) and indefinite (condition-controlled/WHILE) iteration, selecting the appropriate type based on whether the termination condition is fixed or boolean-dependent. Mastery requires the accurate implementation of nested loops for multi-dimensional data traversal and the ability to trace variable states to identify logic errors, such as off-by-one errors or infinite loops.

    0
    Objectives
    3
    Exam Tips
    4
    Pitfalls
    5
    Key Terms
    5
    Mark Points

    What You Need to Demonstrate

    Key skills and knowledge for this topic

    • Award 1 mark for correct initialization of the loop control variable before entry into a WHILE loop
    • Award 1 mark for a boolean condition that correctly terminates the loop at the intended boundary
    • Award 1 mark for indentation or syntax that clearly defines the scope of the code block within the iteration
    • Award 1 mark for updating the loop control variable within the body of a WHILE loop to prevent infinite execution
    • Credit responses that correctly nest iteration structures, ensuring the inner loop completes fully for each step of the outer loop

    Marking Points

    Key points examiners look for in your answers

    • Award 1 mark for correct initialization of the loop control variable before entry into a WHILE loop
    • Award 1 mark for a boolean condition that correctly terminates the loop at the intended boundary
    • Award 1 mark for indentation or syntax that clearly defines the scope of the code block within the iteration
    • Award 1 mark for updating the loop control variable within the body of a WHILE loop to prevent infinite execution
    • Credit responses that correctly nest iteration structures, ensuring the inner loop completes fully for each step of the outer loop

    Examiner Tips

    Expert advice for maximising your marks

    • 💡When completing a trace table, explicitly write the value of the loop counter for every iteration, including the final value that causes the loop to terminate
    • 💡Use a FOR loop specifically when the number of iterations is known or fixed; reserve WHILE loops for validation or when termination depends on user input
    • 💡Check boundary values in range functions carefully; remember that in Python-style pseudocode, range(0, 5) stops at 4, not 5

    Common Mistakes

    Pitfalls to avoid in your exam answers

    • Confusing the syntax or logic of FOR loops (count-controlled) with WHILE loops (condition-controlled), particularly regarding initialization
    • Committing 'off-by-one' errors in trace tables, often by executing the loop body one time too many or too few
    • Failing to update the variable used in the condition of a WHILE loop, resulting in an infinite loop logic error
    • Incorrectly assuming the scope of the loop includes lines of code that are actually outside the indentation level

    Key Terminology

    Essential terms to know

    Likely Command Words

    How questions on this topic are typically asked

    Write
    Trace
    Explain
    Complete
    Correct

    Practical Links

    Related required practicals

    • {"code":"Programming Skill 4","title":"Use of iteration","relevance":"Fundamental construct for algorithm efficiency and data processing"}

    Ready to test yourself?

    Practice questions tailored to this topic