How many times a FOR loop runs
The number of times a FOR loop runs. FOR i ← 1 TO 5 runs 5 times, 3 TO 3 runs once, and 5 TO 1 runs zero times because the start value is bigger than the end value.
Understanding How many times a FOR loop runs in IGCSE Computer Science Paper 2
What it does: 3 - 3 + 1 = 1, so the body runs one time with i equal to 3 and then the loop finishes. The loop runs 5 - 1 + 1 = 5 times. i takes the values 1, 2, 3, 4 and 5. You must add 1 because both the start value and the end value are used. Forgetting the + 1 is a classic off-by-one mistake. 1 TO 10 runs 10 - 1 + 1 = 10 times. 1 TO 9 would run only 9 times, which is an off-by-one error. 7 - 2 + 1 = 6. The values of i are 2, 3, 4, 5, 6 and 7. Subtracting without adding 1 gives the wrong answer of 5.
Common mistakes: Assignment uses the arrow ←, not =. The line should be Count ← Count + 1, so Count goes up by 1 on each of the 5 runs of the loop. The loop should run exactly once, which happens when the start and end values are equal. It should be FOR i ← 3 TO 3. With 3 TO 2 the start is bigger than the end, so the loop runs zero times.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 166–175) and word search (Modules 166–187).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
end - start + 1Fill in the Blanks
Spot the Error
Student with a class code? Join your class →