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 | |
|---|---|---|
| 1REPEAT INPUT Mark Total ← Total + Mark UNTIL Mark = -1 | AREPEAT INPUT Password UNTIL Password = "abc" | |
| 2WHILE Answer <> "yes" DO OUTPUT "Go again?" INPUT Answer ENDWHILE | BWrong loop type: REPEAT runs with no data. If the first Score is 0 the sentinel is still counted. Use INPUT first, then WHILE Score <> 0 DO. | |
| 3Correct loop type when the body must run at least once: read the password first, then test it | CWrong loop type: WHILE is tested before the first INPUT, so Guess has no value yet. Change to REPEAT INPUT Guess UNTIL Guess = Secret. | |
| 4Correct loop type when the body might not run at all: test the first INPUT before doing any work | DINPUT Mark WHILE Mark <> -1 DO Total ← Total + Mark INPUT Mark ENDWHILE | |
| 5REPEAT INPUT Score Count ← Count + 1 UNTIL Score = 0 | EWHILE tests first, so if Answer has no value yet the check is wrong and the loop may never run. REPEAT ... UNTIL is needed. | |
| 6WHILE Guess <> Secret DO INPUT Guess ENDWHILE | FREPEAT always runs once, so if -1 is the first value typed, it is still added to Total. A WHILE loop is needed here. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
wrong loop type — Using REPEAT when the body must sometimes not run, or WHILE when it must run at least once. REPEAT always runs once; WHILE may run zero times.Count ← 0
WHILE Count < NumItems DO
Count ← Count + 1INPUT Age
WHILE Age < 0 OR Age > 120 DO
OUTPUT "Invalid age"REPEAT
INPUT Password
UNTIL Password = "Secret"REPEAT
INPUT Mark
UNTIL Mark >= 0 AND Mark <= 100INPUT Number
WHILE Number <> 0 DO
Total ← Total + Number