SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
AQA 8525 · Section 3.2 · 3.2.2c

Iteration
Loops

FOR Loop · WHILE Loop · REPEAT UNTIL · Choosing the Right Loop

CSZoneAQA GCSE Computer Science 8525
Three AQA Loop Types

AQA 8525 — Three Types of Loop

🔢
FOR … ENDFOR
Known number of repetitions
WHILE … ENDWHILE
Check condition before each loop
🔄
REPEAT … UNTIL
Always runs at least once
FOR Loop

Count-Controlled Loop

FOR i ← 1 TO 5
  OUTPUT i
ENDFOR

← Outputs: 1, 2, 3, 4, 5
total ← 0
FOR i ← 1 TO 10
  total ← total + i
ENDFOR
OUTPUT total

← Outputs: 55 (sum of 1 to 10)
Use FOR when:You know exactly how many times the loop should run.
WHILE & REPEAT UNTIL

Condition-Controlled Loops

WHILE — pre-condition
count ← 1
WHILE count <= 5
  OUTPUT count
  count ← count + 1
ENDWHILE
May run 0 times if condition is False immediately
REPEAT UNTIL — post-condition
REPEAT
  num ← INT(USERINPUT)
UNTIL num > 0
OUTPUT num
Always runs at least once — good for input validation
Choosing a Loop

Which Loop Should I Use?

SituationBest Loop
Repeat exactly 10 timesFOR 1 TO 10
Loop while password is wrong (check first)WHILE
Ask for valid input (must run at least once)REPEAT UNTIL
⚡ Exam Tip:REPEAT UNTIL is ideal for input validation — it guarantees the prompt is shown at least once.
Exam Practice

Have a go at this question

AQA-style question
Write a program using a REPEAT UNTIL loop that repeatedly asks the user to enter a password until they enter the correct password 'secret'. Output 'Access granted' when correct.
4 marks
REPEAT
  password ← USERINPUT
UNTIL password = 'secret'
OUTPUT 'Access granted'
Key Takeaways

What to Remember

FOR = count-controlled (known repetitions) → ends with ENDFOR
WHILE = pre-condition (may run 0 times) → ends with ENDWHILE
REPEAT UNTIL = post-condition (runs at least once) — ideal for input validation
WHILE checks condition before · REPEAT UNTIL checks after each iteration