Total, count, maximum, minimum and average in one loop
One loop visits each item once, updating the total, count, maximum and minimum together. The average is worked out after the loop ends, as Total / Count.
Understanding Total, count, maximum, minimum and average in one loop in IGCSE Computer Science Paper 2
What it does: Each pass adds the current item to Total and adds 1 to Count, so both are updated together in the same loop. Updates go inside the loop and run for every item. Setting the variables to 0 is initialisation, which belongs before the loop. Starting with the first item means Max and Min begin as real values from the data. Starting Max at 100 and Min at 0 means they can never be replaced by a mark in range. Max is the largest value seen (75) and Min is the smallest (40). The last item is not automatically the maximum or minimum.
Common mistakes: Count must be initialised to 0 before the loop. Starting at 1 makes the final count one too high, so it should be Count ← 0. A counter goes up by 1 for each item. Adding Score[i] turns it into a second total. It should be Count ← Count + 1.
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 286–295) and word search (Modules 275–295).
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
single passFill in the Blanks
Spot the Error
Student with a class code? Join your class →