Selection inside a loop (8.1b)
An IF or CASE placed in a loop body is tested again on every repeat, so each pass can take a different branch depending on the current value.
Understanding Selection inside a loop (8.1b) in IGCSE Computer Science Paper 2
What it does: The IF is in the loop body, so each Mark entered is tested separately and Passes only increases for marks of 50 or more. Day changes on every pass of the loop, so the CASE is re-evaluated each time and outputs Weekend or Weekday as appropriate. MOD gives the remainder. An even number has remainder 0 when divided by 2. DIV gives the whole-number part, so it cannot test for even. Only the statement inside the IF runs when the condition is true. A statement after ENDIF runs on every pass, so it would add all the marks. The IF...ENDIF must sit completely inside the FOR...NEXT, so ENDIF is written before NEXT i.
Common mistakes: A count-controlled loop uses TO to set the end value, so it must be FOR Count ← 1 TO 10. UNTIL belongs to REPEAT…UNTIL. A FOR loop does not use DO. DO belongs to WHILE loops. The line should be FOR N ← 1 TO 20.
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 389–398) and word search (Modules 379–398).
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
IF inside a loopFill in the Blanks
Spot the Error
Student with a class code? Join your class →