You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Iteration means repeating a block of code. Loops are one of the three fundamental programming constructs and are tested extensively in GCSE Computer Science (AQA 3.2 / OCR J277 2.2). This lesson covers the three types of loop you need to know.
Without loops, repeating an action 100 times would require writing the same code 100 times. Iteration lets you write the code once and repeat it as many times as needed — making programs shorter, more efficient, and easier to maintain.
A FOR loop repeats a block of code a known number of times. You use it when you know in advance how many repetitions are needed.
FOR i ← 1 TO 10
OUTPUT i
ENDFOR
This outputs the numbers 1 through 10.
for i in range(1, 11):
print(i)
Important: In Python,
range(1, 11)generates numbers from 1 to 10 (the upper bound is exclusive). In AQA pseudocode,FOR i ← 1 TO 10is inclusive of 10.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.