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 | |
|---|---|---|
| 1IF score >= 50 AND attended = TRUE THEN DISPLAY "Pass" ENDIF | AThe one ELSE covers both failures, so a person who is old enough but has no licence is wrongly told "Too young". | |
| 2IF raining THEN IF windy THEN DISPLAY "Stay in" ELSE DISPLAY "Umbrella" ENDIF ELSE DISPLAY "Go out" ENDIF | BOne action needs both tests, so a single compound condition does the job. | |
| 3Two nested IFs with the same single action can be rewritten as one IF with AND | CNesting is not needed here. There is only one action and no separate ELSE outcomes, so the code is harder to read than necessary. | |
| 4When failing each test needs a different message, nest the IFs with separate ELSE parts | DIF A THEN IF B THEN DISPLAY "Yes" ENDIF ENDIF is the same as IF A AND B THEN DISPLAY "Yes" ENDIF | |
| 5IF age >= 16 AND hasLicence THEN DISPLAY "Drive" ELSE DISPLAY "Too young" ENDIF | EIF age >= 16 THEN IF hasLicence THEN DISPLAY "Drive" ELSE DISPLAY "Get licence" ENDIF ELSE DISPLAY "Too young" ENDIF | |
| 6IF member = TRUE THEN IF spend > 50 THEN DISPLAY "Discount" ENDIF ENDIF | FNesting gives each test its own ELSE outcome, which one AND condition cannot do. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
nested IF vs AND — IF A AND B gives the same result as IF A THEN IF B when one action needs both tests. Use nesting when each test needs its own different ELSE outcome.IF score >= 50 AND attendance >= 80 THEN
OUTPUT "Pass"
ENDIFIF score >= 50 THEN
IF attendance >= 80 THEN
OUTPUT "Pass"IF score >= 50 THEN
IF attendance >= 80 THEN OUTPUT "Pass"
ELSE OUTPUT "Low attendance"IF score >= 50 THEN
IF attendance >= 80 THEN
OUTPUT "Pass"
ENDIF
ENDIFIF hasTicket = TRUE AND age >= 18 THEN
OUTPUT "Enter"
ENDIF