Development preview · Sample courses · No real payments or qualifications issued
← Computing & programming foundations
Computing · Lesson 3 of 3

Repeating with loops

The essentials

A loop repeats instructions. Python’s range(n) produces integers starting at 0 and stopping before n. Trace each iteration to see how a running total changes. No code is executed on this site; these are reading exercises.
Worked example
total = 0 for i in range(3): total = total + i The values of i are 0, 1 and 2. The final total is 3.
Check your understanding

How many iterations does for i in range(4) perform?

Choose one answer
Sign in with ChatGPT to practise

Practice is untimed. Retry as needed. A correct answer marks this sample lesson complete.

← Previous lessonView my learning →