A variable that counts in a loop

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

A variable that counts in a loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where should SET count TO 0 go when you use a counter with a loop?
A Before the loop starts
B Inside the loop
2. Which line makes the counter go up by 1 each time the loop repeats?
A SET count TO 1
B ADD 1 TO count
3. Where should ADD 1 TO count go?
A After the loop
B Inside the loop
4. A loop runs 5 times. Each time it runs ADD 1 TO count. The counter started at 0. What does SHOW count display after the loop?
A 5
B 1
5. When is the best time to SHOW count if you want the total number of repeats?
A After the loop has finished
B Before the loop starts

Match the Pairs

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

Left columnRight column
1SET count TO 0 ASET count TO 0 REPEAT 5 TIMES ADD 1 TO count SHOW count
2ADD 1 TO count BSHOW count
3Show how many times the loop ran by displaying the counter after the loop has finished CMakes the counter go up by one. It goes inside the loop so it grows each time the loop repeats.
4A counter starts at 0, then goes up by 1 each time the loop repeats, then the total is shown at the end DMakes a counter that starts at zero. It goes before the loop so the count begins fresh.
5REPEAT 5 TIMES SET count TO 0 ADD 1 TO count SHOW count ESET count TO 0 is inside the loop, so the counter resets to 0 on every repeat. It must go before the loop so the count can build up.
6SET count TO 0 REPEAT 5 TIMES SHOW count ADD 1 TO count FADD 1 TO count is after the loop and SHOW count is inside it. The counter should go up inside the loop and be shown after the loop.

Definitions

SET count TO 0

Fill in the Blanks

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

1.
SET count TO _ REPEAT 5 TIMES ADD 1 TO count
2.
SET count TO 0 REPEAT 5 TIMES ___ 1 TO count
3.
SET count TO 0 REPEAT 4 TIMES ADD _ TO count
4.
SET count TO 0 REPEAT 6 TIMES: ADD 1 TO count ____ count
5.
SET count TO 0 REPEAT 3 TIMES ADD 1 TO _____

Spot the Error

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

Question 1
A SET count TO 1
B REPEAT 5 TIMES
C ADD 1 TO count
D SHOW count
Question 2
A SET count TO 0
B REPEAT 4 TIMES
C ADD 1 TO count
D SHOW total
Question 3
A SET claps TO 0
B REPEAT 8
C ADD 1 TO claps
D SHOW claps
Question 4
A SET laps TO 0
B REPEAT 5 TIMES
C ADD 0 TO laps
D SHOW laps
Question 5
A SET stars TO 0
B REPEAT UNTIL stars = 0
C ADD 1 TO stars
D SHOW stars

Answer Key

A variable that counts in a loop
Section A: Quick Questions
Q1
A — Before the loop starts
Q2
B — ADD 1 TO count
Q3
B — Inside the loop
Q4
A — 5
Q5
A — After the loop has finished
Section B: Match the Pairs
Q1
SET count TO 0 → Makes a counter that starts at zero. It goes before the loop so the count begins fresh.
Q2
ADD 1 TO count → Makes the counter go up by one. It goes inside the loop so it grows each time the loop repeats.
Q3
Show how many times the loop ran by displaying the counter after the loop has finished → SHOW count
Q4
A counter starts at 0, then goes up by 1 each time the loop repeats, then the total is shown at the end → SET count TO 0 REPEAT 5 TIMES ADD 1 TO count SHOW count
Q5
REPEAT 5 TIMES SET count TO 0 ADD 1 TO count SHOW count → SET count TO 0 is inside the loop, so the counter resets to 0 on every repeat. It must go before the loop so the count can build up.
Q6
SET count TO 0 REPEAT 5 TIMES SHOW count ADD 1 TO count → ADD 1 TO count is after the loop and SHOW count is inside it. The counter should go up inside the loop and be shown after the loop.
Section C: Definitions
Q1
SET count TO 0 — Makes a counter. Set count to 0 before the loop, ADD 1 TO count inside the loop each time it repeats, then SHOW count after the loop.
Section D: Fill in the Blanks
Q1
SET count TO 0 REPEAT 5 TIMES ADD 1 TO count
Q2
SET count TO 0 REPEAT 5 TIMES ADD 1 TO count
Q3
SET count TO 0 REPEAT 4 TIMES ADD 1 TO count
Q4
SET count TO 0 REPEAT 6 TIMES: ADD 1 TO count SHOW count
Q5
SET count TO 0 REPEAT 3 TIMES ADD 1 TO count
Section E: Spot the Error
Q1
A — A counter must start at 0 before the loop. Starting at 1 makes the final count one too big. It should be SET count TO 0.
Q2
D — The counter is called count, but this line shows a variable called total that was never made. It should be SHOW count.
Q3
B — The loop line must say how many times to repeat. The word TIMES is missing. It should be REPEAT 8 TIMES.
Q4
C — Adding 0 never changes the counter, so it stays at 0. A counter goes up by 1 each time the loop repeats. It should be ADD 1 TO laps.
Q5
B — stars starts at 0, so the loop would stop straight away and never repeat. The loop should run until stars = 7.