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

Knowledge organisers / Iteration

WHILE loops

All topicsPractise exam questions
Knowledge organiser

Iteration

301.10b

Repeat while condition true.

What you need to know

A while loop repeats as long as its condition is True. The condition is checked before each iteration. Use it when you don't know in advance how many times to loop.

Key points

  • while condition: repeats while True
  • Condition checked before each iteration
  • Must update something to eventually make condition False
  • If condition never becomes False → infinite loop

Code examples

WHILE loop
python
password = ""
while password != "secret":
    password = input("Enter password: ")
print("Access granted")