else if: chained selection

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

else if: chained selection

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does ELSE IF let an algorithm check another condition after the first was false?
A True
B False
2. Must each ELSE IF include its own condition and THEN?
A True
B False
3. Is ELSEIF written as one word in VCAA pseudocode?
A True
B False
4. Does a chain stop checking conditions once one is found true?
A False
B True
5. Does the final ELSE in a chain need its own condition?
A False
B True

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1ELSE IF mark >= 60 THEN AThe ELSE IF condition is missing THEN after it
2ELSE DISPLAY "C" BELSE IF must be written as two separate words, not ELSEIF
3A keyword used to chain another condition onto a selection block CEND IF
4The single keyword pair that closes an entire chained selection block DELSE IF
5IF x = 1 THEN DISPLAY "One" ELSEIF x = 2 THEN DISPLAY "Two" EChecks another condition after the first one was false
6IF n < 5 THEN DISPLAY "Small" ELSE IF n < 10 DISPLAY "Medium" FThe final branch that runs when no earlier condition matched

Definitions

ELSE IF

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF x > 90 THEN DISPLAY "A" _______ x > 50 THEN
2.
ELSE IF y < 10 THEN DISPLAY "Low" ______
3.
ELSE IF a = 2 THEN DISPLAY "Two" ____
4.
ELSE IF score >= 70 ____
5.
_______ n = 3 THEN

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A ELSEIF x > 5 THEN
B DISPLAY "Medium"
C ELSE
D DISPLAY "Small"
Question 2
A IF a = 1 THEN
B PRINT "One"
C ELSE IF a = 2 THEN
D DISPLAY "Two"
Question 3
A IF score >= 90 THEN
B DISPLAY "A"
C ELSE IF score >= 70
D DISPLAY "B"
Question 4
A IF code = 1 THEN
B DISPLAY "Type A"
C ELSE IF code = 2 THEN
D DISPLAY("Type B")
Question 5
A IF hour < 12 THEN
B DISPLAY "Morning"
C ELSE IF hour < 18 THEN
D DISPLAY "Afternoon"
E ENDIF

Answer Key

else if: chained selection
Section A: Quick Questions
Q1
A — True
Q2
A — True
Q3
B — False
Q4
B — True
Q5
A — False
Section B: Match the Pairs
Q1
ELSE IF mark >= 60 THEN → Checks another condition after the first one was false
Q2
ELSE DISPLAY "C" → The final branch that runs when no earlier condition matched
Q3
A keyword used to chain another condition onto a selection block → ELSE IF
Q4
The single keyword pair that closes an entire chained selection block → END IF
Q5
IF x = 1 THEN DISPLAY "One" ELSEIF x = 2 THEN DISPLAY "Two" → ELSE IF must be written as two separate words, not ELSEIF
Q6
IF n < 5 THEN DISPLAY "Small" ELSE IF n < 10 DISPLAY "Medium" → The ELSE IF condition is missing THEN after it
Section C: Definitions
Q1
ELSE IF — A keyword that adds another condition to check if the previous IF or ELSE IF condition was false
Section D: Fill in the Blanks
Q1
IF x > 90 THEN DISPLAY "A" ELSE IF x > 50 THEN
Q2
ELSE IF y < 10 THEN DISPLAY "Low" END IF
Q3
ELSE IF a = 2 THEN DISPLAY "Two" ELSE
Q4
ELSE IF score >= 70 THEN
Q5
ELSE IF n = 3 THEN
Section E: Spot the Error
Q1
A — ELSE IF must be written as two separate words, not ELSEIF.
Q2
B — VCAA pseudocode uses DISPLAY to output a value, not PRINT.
Q3
C — The ELSE IF condition is missing THEN — it should read ELSE IF score >= 70 THEN.
Q4
D — DISPLAY should not use parentheses; it should be written as DISPLAY "Type B".
Q5
E — The closing keyword should be written as END IF, not ENDIF.