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 i from 1 to 3 for j from 1 to 2 print i, j | ATotal passes were found by adding the loop counts. Nested loops need the repeats multiplied, not added. | |
| 2for a from 1 to 4 for b from 1 to 5 count <- count + 1 | BThe trace changes the outer and inner variables together. The inner loop must finish all of j = 1 to 3 before i changes to 2. | |
| 3In a trace table, the outer variable stays the same while the inner variable changes through all its values | CAfter tracing the whole algorithm, count ends at 20 because the inner loop completes 5 passes for each of the 4 outer passes | |
| 4To count total passes of a nested loop, multiply the outer repeats by the inner repeats | DThe inner loop runs j = 1, 2 in full for every value of i, so the print line runs 6 times in total | |
| 5for i from 1 to 2 for j from 1 to 3 print i, j Trace: (1,1) (2,2) (1,3) | Ei=1, j=1 i=1, j=2 i=1, j=3 i=2, j=1 | |
| 6for i from 1 to 4 for j from 1 to 3 print i, j Total passes = 4 + 3 = 7 | Ffor x from 1 to 6 for y from 1 to 2 print x, y (6 x 2 = 12 passes) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
nested loop — A loop inside another loop. When tracing, the inner loop completes all its repeats for each single repeat of the outer loop, so total passes = outer repeats x inner repeats.for i from 1 to 3
for j from 1 to 2
print i, jfor i from 1 to 3
for j from 1 to 4
count ← count + 1for i from 1 to 2
for j from 1 to 3
print i, jfor i from 1 to 3
for j from 1 to i
print jfor a from 1 to 2
for b from 1 to 3
count ← count + 1