CASE OF ... ENDCASE (7a)

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

CASE OF ... ENDCASE (7a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly starts a CASE structure that tests a variable called Grade?
A CASE OF Grade
B CASE Grade THEN
2. Where does the OTHERWISE clause go in a CASE structure?
A First, straight after CASE OF
B Last, just before ENDCASE
3. What does OTHERWISE do?
A Runs its statement when no case value matches
B Runs its statement every time, after the matching case
4. Which keyword closes a CASE structure?
A ENDIF
B ENDCASE
5. Which case line is written correctly in Cambridge pseudocode?
A 2 : OUTPUT "Two"
B 2 : OUTPUT "Two" ENDIF

Match the Pairs

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

Left columnRight column
1OTHERWISE : OUTPUT "Invalid" AOTHERWISE is not the last clause. It must come after all the case values, so the 2 case should be placed before it.
2ENDCASE BCASE OF Day 1 : OUTPUT "Mon" 2 : OUTPUT "Tue" OTHERWISE : OUTPUT "Other" ENDCASE
3Each case has one value, then a colon, then the statement to run when the variable equals that value. CThe last clause of a CASE structure. It runs only if no case value matches the variable.
4OTHERWISE is written last, after every case value, and covers all values that do not match. DCASE OF Grade "A" : OUTPUT "Top" "B" : OUTPUT "Good" ENDCASE
5CASE OF Choice 1 : OUTPUT "Start" OTHERWISE : OUTPUT "Error" 2 : OUTPUT "Stop" ENDCASE ECloses the CASE OF structure.
6CASE OF Choice 1 : OUTPUT "Start" 2 : OUTPUT "Stop" ENDIF FThe structure is closed with ENDIF instead of ENDCASE.

Definitions

CASE OF

Fill in the Blanks

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

1.
_______ Choice 1 : OUTPUT "Start" ENDCASE
2.
CASE OF Choice 1 : OUTPUT "Start" _______
3.
2 : OUTPUT "Stop" _________ : OUTPUT "Invalid" ENDCASE
4.
CASE OF Choice 1 _ OUTPUT "Start" ENDCASE
5.
1 : OUTPUT "One" _ : OUTPUT "Two" 3 : OUTPUT "Three"

Spot the Error

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

Question 1
A CASE OF Choice
B 1 : OUTPUT "Start"
C 2 = OUTPUT "Stop"
D OTHERWISE OUTPUT "Error"
E ENDCASE
Question 2
A CASE OF Day
B 1 OUTPUT "Mon"
C 2 : OUTPUT "Tue"
D ENDCASE
Question 3
A CASE OF Mark
B 'A' : OUTPUT "Top"
C 'B' : OUTPUT Good
D OTHERWISE OUTPUT "None"
E ENDCASE
Question 4
A CASE OF Size
B 1 : OUTPUT "Small"
C 2 : OUTPUT "Large"
D ENDIF
Question 5
A CASE OF Answer
B Y : OUTPUT "Yes"
C 'N' : OUTPUT "No"
D OTHERWISE OUTPUT "Unknown"
E ENDCASE

Answer Key

CASE OF ... ENDCASE (7a)
Section A: Quick Questions
Q1
A — CASE OF Grade
Q2
B — Last, just before ENDCASE
Q3
A — Runs its statement when no case value matches
Q4
B — ENDCASE
Q5
A — 2 : OUTPUT "Two"
Section B: Match the Pairs
Q1
OTHERWISE : OUTPUT "Invalid" → The last clause of a CASE structure. It runs only if no case value matches the variable.
Q2
ENDCASE → Closes the CASE OF structure.
Q3
Each case has one value, then a colon, then the statement to run when the variable equals that value. → CASE OF Grade "A" : OUTPUT "Top" "B" : OUTPUT "Good" ENDCASE
Q4
OTHERWISE is written last, after every case value, and covers all values that do not match. → CASE OF Day 1 : OUTPUT "Mon" 2 : OUTPUT "Tue" OTHERWISE : OUTPUT "Other" ENDCASE
Q5
CASE OF Choice 1 : OUTPUT "Start" OTHERWISE : OUTPUT "Error" 2 : OUTPUT "Stop" ENDCASE → OTHERWISE is not the last clause. It must come after all the case values, so the 2 case should be placed before it.
Q6
CASE OF Choice 1 : OUTPUT "Start" 2 : OUTPUT "Stop" ENDIF → The structure is closed with ENDIF instead of ENDCASE.
Section C: Definitions
Q1
CASE OF — Runs the statement beside the first value that matches the variable. An optional OTHERWISE clause, placed last, runs if nothing matches. ENDCASE closes the structure.
Section D: Fill in the Blanks
Q1
CASE OF Choice 1 : OUTPUT "Start" ENDCASE
Q2
CASE OF Choice 1 : OUTPUT "Start" ENDCASE
Q3
2 : OUTPUT "Stop" OTHERWISE : OUTPUT "Invalid" ENDCASE
Q4
CASE OF Choice 1 : OUTPUT "Start" ENDCASE
Q5
1 : OUTPUT "One" 2 : OUTPUT "Two" 3 : OUTPUT "Three"
Section E: Spot the Error
Q1
C — Each case needs a colon between its value and its statement. Line 3 should be 2 : OUTPUT "Stop".
Q2
B — The colon is missing after the value 1. The line should be 1 : OUTPUT "Mon".
Q3
C — The text being output is a string, so it needs double quotes. Line 3 should be 'B' : OUTPUT "Good".
Q4
D — A CASE OF structure is closed with ENDCASE, not ENDIF. Line 4 should be ENDCASE.
Q5
B — The case value is a CHAR literal, so it needs single quotes. Without them Y looks like a variable. It should be 'Y'.