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 | |
|---|---|---|
| 1FOR Count ← 1 TO 9 OUTPUT Count NEXT Count | AThe loop starts at 0 but the array starts at 1, so it makes one extra pass. It should be FOR Index ← 1 TO 6. | |
| 2FOR Index ← 0 TO 4 OUTPUT Scores[Index] NEXT Index | BFOR Count ← 1 TO 5 Total ← Total + Count NEXT Count | |
| 3To output all 10 values in a 1-based array of 10 items, the loop must start at 1 and end at 10. | CThe end value is 9, so the loop stops one time too early and 10 is never added. It should be TO 10. | |
| 4A trace table of a loop shows the value of the counter on each pass and reveals whether the last value is missed. | DFOR Index ← 1 TO 10 OUTPUT Marks[Index] NEXT Index | |
| 5FOR Num ← 1 TO 9 Total ← Total + Num NEXT Num // should add the numbers 1 to 10 | EStarts at 0 on a 1-based array, so Scores[0] does not exist and the loop makes an extra pass. | |
| 6DECLARE Names : ARRAY[1:6] OF STRING FOR Index ← 0 TO 6 OUTPUT Names[Index] NEXT Index | FRuns 9 times, not 10, so it misses the last value. This is an off-by-one error if 10 repeats were needed. |
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 FOR loop with the wrong start or end value runs one time too many or too few, e.g. TO 9 instead of TO 10, or starting at 0 for a 1-based array. Check the bounds with a trace table.FOR Count ← 1 TO 10
OUTPUT Count
NEXT CountFOR Index ← 1 TO 5
OUTPUT Scores[Index]
NEXT IndexFOR Index ← 0 TO 4
OUTPUT Names[Index]
NEXT IndexFOR Count ← 1 TO 3
OUTPUT Count * 2
NEXT CountFOR Student ← 1 TO 20
INPUT Marks[Student]
NEXT Student