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

Knowledge organisers / Iteration

Loop patterns

All topicsPractise exam questions
Knowledge organiser

Iteration

301.10c

Counters, totals, repeat-until.

What you need to know

Common loop patterns include counting occurrences, accumulating a running total, and repeating until a condition is met. These patterns appear in almost every program.

Key points

  • Counter: count = count + 1 inside a loop
  • Running total: total = total + value
  • Repeat-until: set value, while invalid, re-ask
  • Initialise counter/total BEFORE the loop starts

Code examples

Counter and running total
python
total = 0
count = 0
for i in range(5):
    num = int(input("Number: "))
    total += num
    count += 1
print("Sum: " + str(total) + ", Count: " + str(count))