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

Knowledge organisers / Iteration

FOR loops

All topicsPractise exam questions
Knowledge organiser

Iteration

301.10a

Repeat N times.

What you need to know

A for loop repeats a block a fixed number of times. Use range() to generate the sequence of values for the loop variable.

Key points

  • for i in range(n): repeats n times, i = 0,1,...,n-1
  • range(1, 6) gives 1 to 5; range(0, 10, 2) steps by 2
  • Loop variable updates each iteration automatically
  • Use for when you know how many repetitions

Code examples

FOR loop with range
python
for i in range(5):
    print(i)      # 0 1 2 3 4

for i in range(1, 4):
    print(i * 2)  # 2 4 6