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 10 OUTPUT Count NEXT Count | AINPUT Num WHILE Num <> -1 DO Total ← Total + Num INPUT Num ENDWHILE | |
| 2REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100 | BA REPEAT loop: the body must run at least once, so it suits a validation prompt. | |
| 3Read values until a sentinel of -1 is entered, where the loop might not run at all if -1 is entered first | CA FOR loop: the number of repeats is known in advance (exactly 10 times). | |
| 4Ask for a password again and again until the entry is accepted, always asking at least once | DA FOR loop is used when the number of repeats is not known. A WHILE loop with a sentinel value should be used instead. | |
| 5FOR Count ← 1 TO 5 INPUT Num Total ← Total + Num NEXT Count // used when the number of inputs is unknown | EWHILE tests before the body, so the prompt may never run because Age has no value yet. REPEAT ... UNTIL should be used so the input always happens at least once. | |
| 6WHILE Age < 0 OR Age > 120 DO INPUT Age ENDWHILE // validation, Age not yet set | FREPEAT INPUT Password UNTIL Password = "Secret" |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FOR / WHILE / REPEAT — Use FOR when the number of repeats is known, WHILE when the body might run zero times (such as reading until a sentinel), and REPEAT when the body must run at least once (such as validation).FOR Count ← 1 TO 5
OUTPUT Count
NEXT CountINPUT Mark
WHILE Mark <> -1 DO
INPUT MarkREPEAT
INPUT Age
UNTIL Age >= 0 AND Age <= 120FOR Day ← 1 TO 7
INPUT Temp
NEXT DayREPEAT
INPUT Pin
UNTIL Pin = 1234