OTHERWISE in a CASE statement (7c)

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

OTHERWISE in a CASE statement (7c)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which clause in a CASE statement runs when none of the listed values match?
A ELSE
B OTHERWISE
2. Where must OTHERWISE be placed in a CASE statement?
A Last, just before ENDCASE
B First, straight after CASE OF
3. Choice ← 7. The CASE has cases 1, 2 and 3 and then OTHERWISE OUTPUT "Beep". What is output?
A Nothing is output
B Beep
4. Choice ← 7. The CASE has cases 1, 2 and 3 but NO OTHERWISE clause. What happens?
A Nothing happens
B The program shows an error message automatically
5. Choice ← 2. The CASE has 1, 2, 3 and OTHERWISE OUTPUT "Beep". Does the OTHERWISE line run?
A No, because case 2 matched
B Yes, OTHERWISE always runs at the end

Match the Pairs

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

Left columnRight column
1OTHERWISE OUTPUT "Beep" ACASE Choice OF 1 : OUTPUT "Start" OTHERWISE OUTPUT "Beep" ENDCASE
2CASE Choice OF 1 : OUTPUT "Start" 2 : OUTPUT "Stop" ENDCASE BOTHERWISE OUTPUT "Invalid choice"
3OTHERWISE must be the last clause in the CASE statement, just before ENDCASE CThere is no OTHERWISE, so no "Beep" is output when Choice is not 1 or 2. The CASE does nothing.
4OTHERWISE catches every value that is not one of the listed cases, such as an invalid menu choice DA CASE with no OTHERWISE: if Choice is 3, nothing happens
5CASE Choice OF OTHERWISE OUTPUT "Beep" 1 : OUTPUT "Start" ENDCASE EIf the value matches none of the listed cases, output Beep
6CASE Choice OF 1 : OUTPUT "Start" 2 : OUTPUT "Stop" ENDCASE // expects "Beep" for other values FOTHERWISE is placed first. It must be the last clause, after all the listed cases.

Definitions

OTHERWISE

Fill in the Blanks

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

1.
"Y" : OUTPUT "Yes" _________ OUTPUT "Beep" ENDCASE
2.
2 : OUTPUT "Stop" OTHERWISE OUTPUT "Beep" _______
3.
1 : OUTPUT "Go" OTHERWISE ______ "Beep" ENDCASE
4.
CASE __ Key 1 : OUTPUT "Go" OTHERWISE OUTPUT "Beep"
5.
"N" : OUTPUT "North" _________ OUTPUT "Beep" ENDCASE

Spot the Error

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

Question 1
A INPUT Key
B CASE Key
C 1 : OUTPUT "Go"
D OTHERWISE OUTPUT "Beep"
E ENDCASE
Question 2
A CASE OF Colour
B "R" : OUTPUT "Red"
C "G" : OUTPUT "Green"
D ELSE OUTPUT "Beep"
E ENDCASE
Question 3
A CASE OF Key
B OTHERWISE OUTPUT "Beep"
C 2 : OUTPUT "Stop"
D OTHERWISE OUTPUT "Beep"
E ENDCASE
Question 4
A CASE OF Score
B 10 : OUTPUT "Full marks"
C OTHERWISE "Beep"
D ENDCASE
Question 5
A CASE Mode OF
B "R" : OUTPUT "Run"
C OTHERWISE OUTPUT "Beep"
D ENDCASE

Answer Key

OTHERWISE in a CASE statement (7c)
Section A: Quick Questions
Q1
B — OTHERWISE
Q2
A — Last, just before ENDCASE
Q3
B — Beep
Q4
A — Nothing happens
Q5
A — No, because case 2 matched
Section B: Match the Pairs
Q1
OTHERWISE OUTPUT "Beep" → If the value matches none of the listed cases, output Beep
Q2
CASE Choice OF 1 : OUTPUT "Start" 2 : OUTPUT "Stop" ENDCASE → A CASE with no OTHERWISE: if Choice is 3, nothing happens
Q3
OTHERWISE must be the last clause in the CASE statement, just before ENDCASE → CASE Choice OF 1 : OUTPUT "Start" OTHERWISE OUTPUT "Beep" ENDCASE
Q4
OTHERWISE catches every value that is not one of the listed cases, such as an invalid menu choice → OTHERWISE OUTPUT "Invalid choice"
Q5
CASE Choice OF OTHERWISE OUTPUT "Beep" 1 : OUTPUT "Start" ENDCASE → OTHERWISE is placed first. It must be the last clause, after all the listed cases.
Q6
CASE Choice OF 1 : OUTPUT "Start" 2 : OUTPUT "Stop" ENDCASE // expects "Beep" for other values → There is no OTHERWISE, so no "Beep" is output when Choice is not 1 or 2. The CASE does nothing.
Section C: Definitions
Q1
OTHERWISE — The last clause in a CASE statement. It runs when the value matches none of the listed cases, e.g. OTHERWISE OUTPUT "Beep". Without it, nothing happens if there is no match.
Section D: Fill in the Blanks
Q1
"Y" : OUTPUT "Yes" OTHERWISE OUTPUT "Beep" ENDCASE
Q2
2 : OUTPUT "Stop" OTHERWISE OUTPUT "Beep" ENDCASE
Q3
1 : OUTPUT "Go" OTHERWISE OUTPUT "Beep" ENDCASE
Q4
CASE OF Key 1 : OUTPUT "Go" OTHERWISE OUTPUT "Beep"
Q5
"N" : OUTPUT "North" OTHERWISE OUTPUT "Beep" ENDCASE
Section E: Spot the Error
Q1
B — The CASE statement must start with CASE OF so the OTHERWISE clause later has a valid CASE to belong to. The line should be CASE OF Key.
Q2
D — A CASE statement uses OTHERWISE for the clause that runs when nothing matches, not ELSE. The line should be OTHERWISE OUTPUT "Beep".
Q3
B — OTHERWISE must be the last case in the CASE statement. Putting it here, before the other cases, is wrong. Line 2 should be the case 1 : OUTPUT "Go".
Q4
C — The OTHERWISE clause needs a statement to run. OUTPUT is missing, so it should be OTHERWISE OUTPUT "Beep".
Q5
A — The words are in the wrong order. The correct start is CASE OF Mode, before the cases and the OTHERWISE clause.