Following a loop

About this lesson: Following a loop

In short

A FOR loop repeats the steps inside it a fixed number of times. The counter i goes up by 1 each pass. Run it and watch i and total change in the trace table. Change n.

Following a loop

What you'll explore

Counter loops: FOR … NEXT
A FOR loop repeats the steps inside it a fixed number of times. The counter i goes up by 1 each pass.
Condition loops: WHILE … ENDWHILE
A WHILE loop checks its condition before each pass and stops when it becomes false. Run the countdown and note when the condition is checked.
Inside or outside?: What repeats and what runs once
Only the lines inside the loop repeat. Lines before it run once at the start; lines after it run once at the end. Run it and count.
Check yourself: Count the passes
FOR i ← 1 TO 6 OUTPUT "Hi" NEXT i

Also in this lesson

  • Common mix-ups
  • Loop patterns
  • Human loop

Words to know

loop
Steps that repeat.
iteration
Repeating steps; also one pass of a loop.
counter
A variable that counts passes.
condition
A true/false test.
trace table
A table showing values at each step.

Sources

  • BBC Bitesize KS3 Computer Science
  • Raspberry Pi Foundation, Computing curriculum resources

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 4 short steps and a 6-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Reading and repairing pseudocode · Predicting what a loop outputs →

All lessons in Term 1 · Computing · Age 13