Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This IF ... THEN ... ELSE ... ENDIF (7a) worksheet is part of the IGCSE Computer Science 0478 — 7a Program Development Life Cycle 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 | |
|---|---|---|
| 1ELSE | AGives an IF statement a second path that runs when the condition is FALSE | |
| 2IF Score >= 50 THEN Result ← "Pass" ELSE Result ← "Fail" ENDIF | BIF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF | |
| 3When the condition is TRUE, the THEN statements run and the ELSE statements are skipped | CExactly one path runs: Pass if Score is 50 or more, otherwise Fail | |
| 4In Cambridge pseudocode, THEN and ELSE statements are indented two spaces and ELSE lines up with IF | DThe ENDIF is missing, so the IF ... THEN ... ELSE statement is never closed. | |
| 5IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" | EIF Answer = 4 THEN Correct ← TRUE ELSE Correct ← FALSE ENDIF | |
| 6IF Answer = 4 THEN Correct ← TRUE ELSE Answer <> 4 THEN Correct ← FALSE ENDIF | FELSE has a condition and a THEN added to it, but ELSE never takes a condition. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
ELSE — Gives IF a second path. The THEN statements run when the condition is TRUE and the ELSE statements run when it is FALSE. Exactly one path runs, never both.ELSE
Correct ← FALSE
ENDIFELSE
Correct ← FALSE
ENDIFIF Guess = 7 THEN
Correct ← TRUE
ELSEIF Guess = 7 THEN
Correct ← TRUE
ELSEELSE
Correct ← FALSE
ENDIF