Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Pseudocode WHILE ... DO ... ENDWHILE and REPEAT ... UNTIL worksheet is part of the IGCSE Computer Science 0478 — 7b Decomposition and Sub-systems journey. Print it as a booklet?
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 Count < 5 DO Count ← Count + 1 ENDWHILE | AREPEAT must end with UNTIL, not WHILE. UNTIL stops when the condition is true. | |
| 2REPEAT INPUT Password UNTIL Password = "cat" | BREPEAT INPUT Number UNTIL Number > 0 | |
| 3A loop that must ask for a number at least once, then check it afterwards | CWHILE Lives > 0 DO Lives ← Lives - 1 ENDWHILE | |
| 4A loop whose condition is tested first, so it might never run | DTests the condition before each repeat, so the loop body may run 0 times | |
| 5WHILE Total < 100 DO OUTPUT Total ENDWHILE | EThe condition can never change because Total is not updated inside the loop. This makes an infinite loop. | |
| 6REPEAT Count ← Count + 1 WHILE Count = 10 | FRuns the body first and tests after, so it always runs at least once |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
WHILE ... DO ... ENDWHILE — A loop that tests its condition before each repeat, so it may run 0 times. REPEAT ... UNTIL runs the body first and tests after, so it always runs at least once.WHILE Count < 5 DO
Count ← Count + 1
ENDWHILEREPEAT
INPUT Guess
UNTIL Guess = 7WHILE Count < 5 DO
Count ← Count + 1
ENDWHILEWHILE Lives > 0 DO
Lives ← Lives - 1
ENDWHILEREPEAT
INPUT Password
UNTIL Password = "cloodit"