Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Programming Fundamentals

The use of the three basic programming constructs used to control the flow of a program: Iteration (count- and condition-controlled loops)

All topicsPractise exam questions
Knowledge organiser

Programming Fundamentals

2.2.1d

Practical use of the techniques, Understanding of each technique

What you need to know

Iteration means repeating a set of instructions. There are two main types: count-controlled loops (FOR loops) that repeat a fixed number of times, and condition-controlled loops (WHILE and DO-UNTIL) that repeat until a condition changes. Loops can also be nested, meaning one loop inside another.

Key points

  • FOR loops are count-controlled: they repeat a FIXED number of times using a counter variable.
  • WHILE loops are condition-controlled: they check a condition BEFORE each iteration and repeat while it is True.
  • DO-UNTIL loops check the condition AFTER each iteration, so the code always runs at least once.
  • Use a WHILE loop when you don't know in advance how many iterations are needed (e.g. 'repeat until user enters stop').
  • Use a FOR loop when you know exactly how many iterations (e.g. 'ask 3 questions', 'check each item in an array').
  • Loops can be nested: a loop inside another loop (e.g. sorting algorithms have nested loops).
  • Exam Tip:While loops for 'repeat until stop' — the condition must eventually become False. while team != "stop" is common.
  • Exam Tip:Make sure inputs that change the loop condition are INSIDE the loop, not just outside it. A typical mistake is to calculate but not re-ask for input.
  • Exam Tip:Initialise totals/counters BEFORE the loop, not inside it (otherwise they reset each iteration — a classic logic error).
  • Exam Tip:while hours != 0 is safer than while hours > 0 (user could enter -1 and bypass the check).
  • Common Mistake:In Python, for x in list: — x is the item VALUE, not an index. Do not then try to access list[x] as x is not an index number.

Code examples

FOR loop and WHILE loop
python
# FOR loop (count-controlled)
for i in range(5):
    print("Iteration", i)

# WHILE loop (condition-controlled)
password = ""
while password != "secret":
    password = input("Enter password: ")
print("Access granted!")