Describing the processes of a loop

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

Describing the processes of a loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is the better description of FOR Count ← 1 TO 5 with Total ← Total + Count?
A The loop repeats 5 times and each time Count is added to Total
B The loop adds numbers together
2. Which phrase correctly describes the repeat part of: WHILE Mark <> -1 DO ... ENDWHILE?
A It repeats exactly 10 times
B It repeats until the user enters -1
3. A FOR loop runs from 1 to 20. Which describes it best?
A Condition-controlled: it repeats until a condition is met
B Count-controlled: it repeats 20 times
4. Which describes what happens to the data in: Total ← Total + Mark inside a loop?
A Each mark entered is added to Total
B Total is set to the first mark only
5. Which is the better answer to 'Describe the loop'?
A It repeats until Password is correct, asking for a new Password each time
B It is a loop that has a Password in it

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 Total ← Total + Count NEXT Count ARepeats until the user enters -1, adding each mark to Total and then inputting the next mark
2WHILE Mark <> -1 DO Total ← Total + Mark INPUT Mark ENDWHILE BIt does not say how many times the loop repeats or when it stops, so it is too vague.
3A count-controlled loop description gives the number of repeats: it repeats 5 times and each number input is added to Sum CREPEAT INPUT Password UNTIL Password = "Secret"
4A condition-controlled loop description gives the stopping condition: it repeats until the password is correct, asking for a new password each time DFOR Index ← 1 TO 5 INPUT Number Sum ← Sum + Number NEXT Index
5Description: "The loop adds numbers to Total." ERepeats exactly 10 times, and each time round the current value of Count is added to Total
6Description: "The loop repeats 10 times." FIt does not say what happens to the data each time round, such as which value is added or changed.

Definitions

Describing a loop

Fill in the Blanks

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

1.
FOR Count ← 1 TO _ Total ← Total + Mark NEXT Count
2.
WHILE Total < 100 DO Total ← _____ + Mark ENDWHILE
3.
WHILE Count <= 5 DO Count ← Count _ 1 ENDWHILE
4.
FOR Count ← 1 TO 10 ____ 2 OUTPUT Count NEXT Count
5.
REPEAT Total ← Total + Mark _____ Total >= 100

Spot the Error

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

Question 1
A Total ← 0
B FOR Count ← 1 TO 5
C Mark ← INPUT
D Total ← Total + Mark
E NEXT Count
Question 2
A Count ← 0
B WHILE Count > 10 DO
C Count ← Count + 1
D ENDWHILE
Question 3
A Total ← 0
B FOR Day ← 1 TO 7
C INPUT Steps
D Total ← Total + Day
E NEXT Day
Question 4
A Attempts ← 0
B REPEAT
C INPUT Password
D Attempts ← Attempts - 1
E UNTIL Password = Secret
Question 5
A Total ← 0
B FOR Num ← 1 UNTIL 10
C Total ← Total + Num
D NEXT Num
E OUTPUT Total

Answer Key

Describing the processes of a loop
Section A: Quick Questions
Q1
A — The loop repeats 5 times and each time Count is added to Total
Q2
B — It repeats until the user enters -1
Q3
B — Count-controlled: it repeats 20 times
Q4
A — Each mark entered is added to Total
Q5
A — It repeats until Password is correct, asking for a new Password each time
Section B: Match the Pairs
Q1
FOR Count ← 1 TO 10 Total ← Total + Count NEXT Count → Repeats exactly 10 times, and each time round the current value of Count is added to Total
Q2
WHILE Mark <> -1 DO Total ← Total + Mark INPUT Mark ENDWHILE → Repeats until the user enters -1, adding each mark to Total and then inputting the next mark
Q3
A count-controlled loop description gives the number of repeats: it repeats 5 times and each number input is added to Sum → FOR Index ← 1 TO 5 INPUT Number Sum ← Sum + Number NEXT Index
Q4
A condition-controlled loop description gives the stopping condition: it repeats until the password is correct, asking for a new password each time → REPEAT INPUT Password UNTIL Password = "Secret"
Q5
Description: "The loop adds numbers to Total." → It does not say how many times the loop repeats or when it stops, so it is too vague.
Q6
Description: "The loop repeats 10 times." → It does not say what happens to the data each time round, such as which value is added or changed.
Section C: Definitions
Q1
Describing a loop — State how many times the loop repeats or the condition it stops on, and what happens to the data each time round, e.g. each mark is added to Total.
Section D: Fill in the Blanks
Q1
FOR Count ← 1 TO 5 Total ← Total + Mark NEXT Count
Q2
WHILE Total < 100 DO Total ← Total + Mark ENDWHILE
Q3
WHILE Count <= 5 DO Count ← Count + 1 ENDWHILE
Q4
FOR Count ← 1 TO 10 STEP 2 OUTPUT Count NEXT Count
Q5
REPEAT Total ← Total + Mark UNTIL Total >= 100
Section E: Spot the Error
Q1
C — INPUT is a keyword that comes first, followed by the variable. It should be INPUT Mark, so each of the 5 marks is read and then added to Total.
Q2
B — Count starts at 0, so Count > 10 is false straight away and the loop never runs. The loop repeats while Count < 10 and adds 1 to Count each time round.
Q3
D — Each pass should add the steps entered to Total, not the day number. It should be Total ← Total + Steps.
Q4
D — Attempts counts how many times the loop repeats until the password is correct, so it must go up by 1 each pass: Attempts ← Attempts + 1.
Q5
B — A count-controlled loop uses FOR ... TO to give the start and end values. UNTIL belongs to REPEAT loops. It should be FOR Num ← 1 TO 10.