Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1count ← 0 REPEAT UNTIL count > 5 count ← count + 1 | Acount ← 0 REPEAT UNTIL count = 5 count ← count + 1 | |
| 2count ← 1 WHILE count < 5 count ← count + 1 | Bcount ← 1 REPEAT UNTIL count = 5 count ← count + 1 | |
| 3Fix for a loop that runs one time too many: start the counter at 0 and stop when count = 5, giving exactly 5 passes. | CRuns 6 times (count is 0, 1, 2, 3, 4, 5), which is one time too many if the goal was 5 repeats. | |
| 4The start value of the counter matters: starting at 1 instead of 0 with the stop test count = 5 gives only 4 passes. | DThe stop test count > 3 lets the loop run when count is 3, so Hello is said 4 times instead of 3. Use count = 3 as the stop test. | |
| 5Goal: say Hello 3 times count ← 0 REPEAT UNTIL count > 3 OUTPUT "Hello" count ← count + 1 | EThe test count < 4 stops after count 3, so Hi is said only 4 times instead of 5. Use count < 5 so the loop keeps going. | |
| 6Goal: say Hi 5 times count ← 0 WHILE count < 4 OUTPUT "Hi" count ← count + 1 | FRuns only 4 times (count is 1, 2, 3, 4), which is one time too few if the goal was 5 repeats. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
off-by-one error — A bug where a repeat count or stop test is wrong by one, such as count > 5 instead of count = 5, so the loop body runs one time too many or one time too few.count ← 1
REPEAT UNTIL count > 5
count ← count + 1count ← 0
REPEAT UNTIL count = 5
count ← count + 1// Trace table must show 5 rows
REPEAT 5 TIMES
OUTPUT "Go"count ← 0
WHILE count < 3
count ← count + 1count ← 0
REPEAT UNTIL count = 4
count ← count + 1