Using the FOR counter inside the loop

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

Using the FOR counter inside the loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does this output? FOR Count ← 1 TO 3 / OUTPUT Count / NEXT Count
A 1, 2, 3 (a new value each repeat)
B 3, 3, 3 (the final value every time)
2. FOR Count ← 1 TO 4 / OUTPUT Count * 7 / NEXT Count. What are the first two values output?
A 7 then 14
B 7 then 7
3. Which loop body outputs the 7 times table from 1 * 7 to 12 * 7?
A OUTPUT 12 * 7 (inside FOR Count ← 1 TO 12)
B OUTPUT Count * 7 (inside FOR Count ← 1 TO 12)
4. On the 3rd repeat of FOR Count ← 1 TO 10 with OUTPUT Count * 7, what is output?
A 21
B 7
5. Which statement should NOT appear inside a FOR Count loop body?
A OUTPUT Count * 7
B Count ← Count + 2

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 5 OUTPUT Count NEXT Count AFOR Count <- 1 TO 3 OUTPUT Count NEXT Count OUTPUT Count
2OUTPUT Count * 7 BOutputs the counter's value on each repeat, so it displays 1, 2, 3, 4, 5, one number per line
3The counter must not be changed by an assignment inside the loop body; the FOR loop controls it CThe counter is changed inside the loop with an assignment. The FOR loop controls Count, so the body must never assign to it.
4After the loop finishes, the counter keeps its last value, so it can be output after NEXT DThe times table uses a fixed value instead of the counter, so it does not show a new multiple on each repeat.
5FOR Count <- 1 TO 5 Count <- Count + 1 OUTPUT Count NEXT Count EFOR Count <- 1 TO 12 OUTPUT Count * 7 NEXT Count
6FOR Count <- 1 TO 12 OUTPUT Count * 7 NEXT Count OUTPUT 7 FUses the counter in a calculation inside the loop, so each repeat outputs the next multiple of 7 (a times table)

Definitions

OUTPUT Count * 7

Fill in the Blanks

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

1.
FOR Count ← 1 TO 5 OUTPUT _____ NEXT Count
2.
FOR Count ← 1 TO 12 OUTPUT Count _ 7 NEXT Count
3.
FOR Count ← 1 TO 12 OUTPUT Count * 7 NEXT _____
4.
FOR Count ← 1 TO 12 OUTPUT Count * 7 ____ Count
5.
FOR Count ← _ TO 12 OUTPUT Count * 7 NEXT Count

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 Count
Question 2
A FOR Count <- 1 TO 12
B OUTPUT Counter * 7
C NEXT Count
Question 3
A FOR Count <- 1 UNTIL 10
B OUTPUT Count * 3
C NEXT Count
Question 4
A FOR Count <- 1 TO 5
B OUTPUT Count * 2
C NEXT Total
Question 5
A Total <- 0
B FOR Count <- 1 TO 4
C Total <- Total + Count
D Count <- Count + 1
E NEXT Count

Answer Key

Using the FOR counter inside the loop
Section A: Quick Questions
Q1
A — 1, 2, 3 (a new value each repeat)
Q2
A — 7 then 14
Q3
B — OUTPUT Count * 7 (inside FOR Count ← 1 TO 12)
Q4
A — 21
Q5
B — Count ← Count + 2
Section B: Match the Pairs
Q1
FOR Count <- 1 TO 5 OUTPUT Count NEXT Count → Outputs the counter's value on each repeat, so it displays 1, 2, 3, 4, 5, one number per line
Q2
OUTPUT Count * 7 → Uses the counter in a calculation inside the loop, so each repeat outputs the next multiple of 7 (a times table)
Q3
The counter must not be changed by an assignment inside the loop body; the FOR loop controls it → FOR Count <- 1 TO 12 OUTPUT Count * 7 NEXT Count
Q4
After the loop finishes, the counter keeps its last value, so it can be output after NEXT → FOR Count <- 1 TO 3 OUTPUT Count NEXT Count OUTPUT Count
Q5
FOR Count <- 1 TO 5 Count <- Count + 1 OUTPUT Count NEXT Count → The counter is changed inside the loop with an assignment. The FOR loop controls Count, so the body must never assign to it.
Q6
FOR Count <- 1 TO 12 OUTPUT Count * 7 NEXT Count OUTPUT 7 → The times table uses a fixed value instead of the counter, so it does not show a new multiple on each repeat.
Section C: Definitions
Q1
OUTPUT Count * 7 — Uses the FOR counter inside the loop body. Count holds a new value on each repeat, so this outputs a times table. Never change Count inside the loop; after the loop it keeps its last value.
Section D: Fill in the Blanks
Q1
FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Q2
FOR Count ← 1 TO 12 OUTPUT Count * 7 NEXT Count
Q3
FOR Count ← 1 TO 12 OUTPUT Count * 7 NEXT Count
Q4
FOR Count ← 1 TO 12 OUTPUT Count * 7 NEXT Count
Q5
FOR Count ← 1 TO 12 OUTPUT Count * 7 NEXT Count
Section E: Spot the Error
Q1
A — The FOR loop gives the counter its start value with the assignment arrow <-, not =. It should be FOR Count <- 1 TO 5.
Q2
B — The loop counter is called Count, so Counter is a different variable that was never given a value. It should be OUTPUT Count * 7.
Q3
A — A FOR loop uses the keyword TO before the end value, not UNTIL. UNTIL belongs to REPEAT...UNTIL. It should be FOR Count <- 1 TO 10.
Q4
C — NEXT must name the same counter as the FOR line. The counter is Count, so it should be NEXT Count.
Q5
D — The counter must never be changed inside the loop, because the FOR loop already adds 1 each repeat. This line would break the counting. It should be OUTPUT Total.