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.

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
← Reading and repairing pseudocode · Predicting what a loop outputs →