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 30 INPUT Mark NEXT Count | AA FOR loop is the wrong choice because the number of attempts is not known in advance. The user should be asked until the password is correct, so use REPEAT...UNTIL Password = "open". | |
| 2REPEAT INPUT Password UNTIL Password = "open" | BA post-condition loop: use it when the body must run at least once, such as asking for input before checking it. | |
| 3Read numbers until the rogue value -1 is entered; the loop may run zero times if -1 is typed first, so use a pre-condition loop. | CREPEAT INPUT Age UNTIL Age >= 0 AND Age <= 120 | |
| 4Validate an input so that the user is always asked at least once and asked again until the value is acceptable. | DA count-controlled loop: use it when the number of repeats is known in advance, such as 30 students. | |
| 5WHILE Count <= 10 DO OUTPUT Count ENDWHILE | ECount is never given a start value and never increased, so the loop never ends (or never starts). The number of repeats is known, so a FOR loop is the better choice: FOR Count <- 1 TO 10. | |
| 6FOR Attempt <- 1 TO 100 INPUT Password NEXT Attempt | FINPUT Num WHILE Num <> -1 DO Total <- Total + Num INPUT Num ENDWHILE |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FOR, WHILE or REPEAT — Choose FOR when the number of repeats is known, WHILE when the loop may run zero times, and REPEAT...UNTIL when the loop must run at least once.FOR Count ← 1 TO 10
OUTPUT Count
NEXT CountWHILE Num <> -1 DO
Total ← Total + Num
ENDWHILEREPEAT
INPUT Age
UNTIL Age >= 1 AND Age <= 120REPEAT
INPUT Password
UNTIL Password = "open"FOR Student ← 1 TO 30
INPUT Mark
NEXT Student