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 | |
|---|---|---|
| 1WHILE Total < 10 DO Total ← Total + 4 ENDWHILE | AThe student ran the body without testing first. X < 5 is false at the start (8 is not less than 5), so the body never runs and X stays 8. | |
| 2REPEAT INPUT Guess UNTIL Guess = 7 | BREPEAT tests after the body, so the body always runs once. N becomes 11, and then N > 5 is true, so the loop stops after one pass. | |
| 3When tracing a loop that reads input, use the next test input on each pass and stop when the sentinel value is read. | CCount ← 1 WHILE Count < 5 DO OUTPUT Count ENDWHILE | |
| 4A loop whose condition never changes to end it will never stop, so the trace table keeps adding rows forever. | DThe body runs first and the condition Guess = 7 is tested AFTER it, so the loop runs at least once and stops when the condition is true. | |
| 5Trace of: X ← 8 WHILE X < 5 DO X ← X + 1 ENDWHILE Trace shows X = 9 after the loop | EINPUT Num WHILE Num <> -1 DO Total ← Total + Num INPUT Num ENDWHILE | |
| 6Trace of: N ← 10 REPEAT N ← N + 1 UNTIL N > 5 Trace shows the loop does not run | FThe condition Total < 10 is tested BEFORE each pass of the body, so the body may run zero times. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
WHILE and REPEAT loop trace — Trace a loop by testing its condition each pass: WHILE tests before the body and may never run; REPEAT tests after the body so runs once at least. Stop when the loop ends.WHILE Count < 3 DO
Count ← Count + 1
ENDWHILEREPEAT
Count ← Count + 1
UNTIL Count = 3Count ← 5
WHILE Count < 3 DO
OUTPUT CountREPEAT
INPUT Value
UNTIL Value = 0WHILE Count < 3 DO
Count ← Count + 1
ENDWHILE