FOR…TO…NEXT count-controlled loop

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

FOR…TO…NEXT count-controlled loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly closes this loop? FOR Count <- 1 TO 10
A NEXT Count
B ENDFOR Count
2. How many times does this loop run? FOR Count <- 1 TO 10
A 10 times
B 9 times
3. How many times does this loop run? FOR Num <- 3 TO 7
A 5 times
B 4 times
4. Which NEXT line matches this loop? FOR Index <- 1 TO 5
A NEXT Count
B NEXT Index
5. By how much does the counter change each time round a FOR loop with no STEP?
A It goes up by 2
B It goes up by 1

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1FOR Count <- 1 TO 10 AFOR Count <- 1 TO 5 OUTPUT Count NEXT Count
2NEXT Count BThe loop has no NEXT Count line, so it is never closed.
3A loop that must run exactly 5 times, with the counter going 1 to 5 CStarts a loop that repeats the indented lines 10 times, with Count going 1, 2, 3 ... 10
4A loop from 3 to 7 runs 5 times because end - start + 1 = 5 DEnds the FOR loop and names the same counter that the FOR line used
5FOR Count <- 1 TO 10 OUTPUT Count NEXT Counter ENEXT names a different variable (Counter) from the one in the FOR line (Count). The counter names must match.
6FOR Count <- 1 TO 10 OUTPUT Count FFOR Num <- 3 TO 7 OUTPUT Num NEXT Num

Definitions

FOR Count <- 1 TO 10

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
FOR Count __ 1 TO 10 OUTPUT Count NEXT Count
2.
FOR Count <- 1 __ 10 OUTPUT Count NEXT Count
3.
FOR Count <- 1 TO 5 OUTPUT "Hello" ____ Count
4.
FOR Count <- 1 TO 10 OUTPUT Count * 2 NEXT _____
5.
FOR Num <- 1 TO _ OUTPUT "Go" NEXT Num

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A FOR Count <- 1 TO 5
B OUTPUT Count
C NEXT Total
Question 2
A FOR Num = 1 TO 3
B OUTPUT Num * 2
C NEXT Num
Question 3
A Total <- 0
B FOR Count <- 1 UNTIL 4
C Total <- Total + Count
D NEXT Count
E OUTPUT Total
Question 4
A FOR Count <- 1 TO 6
B OUTPUT Count
C ENDFOR
Question 5
A Sum <- 0
B FOR Index <- TO 10
C INPUT Mark
D Sum <- Sum + Mark
E NEXT Index

Answer Key

FOR…TO…NEXT count-controlled loop
Section A: Quick Questions
Q1
A — NEXT Count
Q2
A — 10 times
Q3
A — 5 times
Q4
B — NEXT Index
Q5
B — It goes up by 1
Section B: Match the Pairs
Q1
FOR Count <- 1 TO 10 → Starts a loop that repeats the indented lines 10 times, with Count going 1, 2, 3 ... 10
Q2
NEXT Count → Ends the FOR loop and names the same counter that the FOR line used
Q3
A loop that must run exactly 5 times, with the counter going 1 to 5 → FOR Count <- 1 TO 5 OUTPUT Count NEXT Count
Q4
A loop from 3 to 7 runs 5 times because end - start + 1 = 5 → FOR Num <- 3 TO 7 OUTPUT Num NEXT Num
Q5
FOR Count <- 1 TO 10 OUTPUT Count NEXT Counter → NEXT names a different variable (Counter) from the one in the FOR line (Count). The counter names must match.
Q6
FOR Count <- 1 TO 10 OUTPUT Count → The loop has no NEXT Count line, so it is never closed.
Section C: Definitions
Q1
FOR Count <- 1 TO 10 — A count-controlled loop that repeats the indented lines end - start + 1 times, adding 1 to the counter each time. It is closed by NEXT Count, which names the same counter.
Section D: Fill in the Blanks
Q1
FOR Count <- 1 TO 10 OUTPUT Count NEXT Count
Q2
FOR Count <- 1 TO 10 OUTPUT Count NEXT Count
Q3
FOR Count <- 1 TO 5 OUTPUT "Hello" NEXT Count
Q4
FOR Count <- 1 TO 10 OUTPUT Count * 2 NEXT Count
Q5
FOR Num <- 1 TO 5 OUTPUT "Go" NEXT Num
Section E: Spot the Error
Q1
C — NEXT must name the same counter that FOR started with. It should be NEXT Count, not NEXT Total.
Q2
A — A FOR loop gives the counter its start value with the assignment arrow <-, not =. It should be FOR Num <- 1 TO 3.
Q3
B — A FOR loop uses the keyword TO between the start and end values. UNTIL belongs to REPEAT...UNTIL. It should be FOR Count <- 1 TO 4.
Q4
C — Cambridge pseudocode closes a FOR loop with NEXT followed by the counter name, not ENDFOR. It should be NEXT Count.
Q5
B — The FOR line needs a start value after <-. It should be FOR Index <- 1 TO 10, so the loop runs 10 times.