Counting: how it works

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

Counting: how it works

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Before a counting loop starts, what should the counter be set to?
A Count ← 0
B Count ← 1
2. Each time an item is counted, what is added to the counter?
A Count ← Count + Mark[Index]
B Count ← Count + 1
3. Which statement about counting is TRUE?
A Counting adds 1 each time something happens
B Counting adds the value of each item to the counter
4. An array holds 5 test marks (60, 45, 80, 92, 70). The algorithm counts every mark. What is Count at the end?
A 5
B 347
5. Which algorithm counts only the marks above 50?
A Count ← Count + 1 for every mark, with no IF
B IF Mark[Index] > 50 THEN Count ← Count + 1 ENDIF

Match the Pairs

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

Left columnRight column
1Count ← 0 AThe counter is reset to 0 inside the loop, so it never builds up past 1. It must be set to 0 once, before the loop.
2Count ← Count + 1 BAdds 1 to the counter each time it runs, no matter what the item's value is
3Count only the items that meet a condition, such as marks over 50 CThis adds the item's value to the counter instead of adding 1. That is totalling, not counting.
4Count every item by adding 1 on each repeat of the loop DFOR Index ← 1 TO 10 Count ← Count + 1 NEXT Index
5Count ← Count + Mark[Index] ESets the counter to 0 before the loop starts, so nothing has been counted yet
6FOR Index ← 1 TO 10 Count ← 0 Count ← Count + 1 NEXT Index FIF Mark[Index] > 50 THEN Count ← Count + 1 ENDIF

Definitions

Count ← Count + 1

Fill in the Blanks

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

1.
Count ← _ FOR Index ← 1 TO 10 Count ← Count + 1
2.
Count ← 0 FOR Index ← 1 TO 10 Count ← Count + _
3.
FOR Index ← 1 TO 10 Count ← _____ + 1 NEXT Index
4.
IF Score _ 50 THEN Count ← Count + 1 ENDIF
5.
IF Colour = "Red" THEN Count ← Count + 1 _____

Spot the Error

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

Question 1
A Count ← 0
B FOR Index ← 1 TO 10
C INPUT Mark
D Count ← Count + Mark
E NEXT Index
F OUTPUT Count
Question 2
A Count ← 0
B FOR Index ← 1 TO 10
C IF Mark[Index] = 50 THEN
D Count ← Count + 1
E ENDIF
F NEXT Index
Question 3
A INPUT Mark
B Count ← 1
C WHILE Mark <> -1 DO
D Count ← Count + 1
E INPUT Mark
F ENDWHILE
Question 4
A Count ← 5
B REPEAT
C INPUT Number
D Count ← Count + 1
E UNTIL Count = 10
F OUTPUT Count
Question 5
A Count ← 0
B FOR Index ← 1 TO Count
C IF Age[Index] >= 18 THEN
D Count ← Count + 1
E ENDIF
F NEXT Index

Answer Key

Counting: how it works
Section A: Quick Questions
Q1
A — Count ← 0
Q2
B — Count ← Count + 1
Q3
A — Counting adds 1 each time something happens
Q4
A — 5
Q5
B — IF Mark[Index] > 50 THEN Count ← Count + 1 ENDIF
Section B: Match the Pairs
Q1
Count ← 0 → Sets the counter to 0 before the loop starts, so nothing has been counted yet
Q2
Count ← Count + 1 → Adds 1 to the counter each time it runs, no matter what the item's value is
Q3
Count only the items that meet a condition, such as marks over 50 → IF Mark[Index] > 50 THEN Count ← Count + 1 ENDIF
Q4
Count every item by adding 1 on each repeat of the loop → FOR Index ← 1 TO 10 Count ← Count + 1 NEXT Index
Q5
Count ← Count + Mark[Index] → This adds the item's value to the counter instead of adding 1. That is totalling, not counting.
Q6
FOR Index ← 1 TO 10 Count ← 0 Count ← Count + 1 NEXT Index → The counter is reset to 0 inside the loop, so it never builds up past 1. It must be set to 0 once, before the loop.
Section C: Definitions
Q1
Count ← Count + 1 — Counting adds 1 to a counter each time something happens. Start the counter at 0, add 1 (not the item's value), and do it for every item or only for matches.
Section D: Fill in the Blanks
Q1
Count ← 0 FOR Index ← 1 TO 10 Count ← Count + 1
Q2
Count ← 0 FOR Index ← 1 TO 10 Count ← Count + 1
Q3
FOR Index ← 1 TO 10 Count ← Count + 1 NEXT Index
Q4
IF Score > 50 THEN Count ← Count + 1 ENDIF
Q5
IF Colour = "Red" THEN Count ← Count + 1 ENDIF
Section E: Spot the Error
Q1
D — Counting adds 1 each time, not the item's value. Adding Mark makes a total, not a count. It should be Count ← Count + 1.
Q2
C — The condition only matches marks of exactly 50, so passes above 50 are missed. To count every pass it should be IF Mark[Index] >= 50 THEN.
Q3
B — A counter must start at 0. Starting at 1 makes every answer one too high. It should be Count ← 0.
Q4
A — The counter must start at 0 before counting begins. Starting at 5 gives a wrong count. It should be Count ← 0.
Q5
B — The loop must check all 20 items, but Count is 0 at the start so the loop would not check them. It should be FOR Index ← 1 TO 20.