CASE OF…ENDCASE (8.1b)

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

CASE OF…ENDCASE (8.1b)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly starts a CASE statement that tests the variable Choice?
A CASE Choice THEN
B CASE OF Choice
2. Which keyword closes a CASE statement?
A ENDCASE
B ENDIF
3. Which is the correct way to write one value and its statement inside a CASE?
A 1 : OUTPUT "Start"
B 1 THEN OUTPUT "Start"
4. How should the values be laid out inside a CASE statement?
A One value per line, each with its own statement
B All the values on one line, separated by commas
5. What does CASE OF Choice do when Choice has the value 2?
A Runs every statement in the CASE one after another
B Runs the statement beside the value 2

Match the Pairs

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

Left columnRight column
1CASE OF Choice AStarts a CASE statement that compares the variable Choice with a list of values
2ENDCASE BCloses the CASE statement after the last value has been listed
3Each value is written with a colon, then the statement that runs when the variable matches that value CCASE OF Grade 'A' : OUTPUT "Top" 'B' : OUTPUT "Good" ENDCASE
4A CASE statement can test a CHAR variable, with each CHAR value written one per line D1 : OUTPUT "Start"
5CASE OF Choice 1 : OUTPUT "Start" 2 : OUTPUT "Quit" EENDCASE is missing, so the CASE statement is never closed. Add ENDCASE after the last value.
6CASE OF Choice 1 OUTPUT "Start" 2 OUTPUT "Quit" ENDCASE FThe colon is missing between each value and its statement. It should be 1 : OUTPUT "Start".

Definitions

CASE OF Choice

Fill in the Blanks

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

1.
____ OF Choice 1 : OUTPUT "Start" ENDCASE
2.
CASE OF ______ 1 : OUTPUT "Start" ENDCASE
3.
CASE OF Choice 2 : OUTPUT "Quit" _______
4.
CASE OF Grade 'A' _ OUTPUT "Top mark" ENDCASE
5.
CASE OF Choice 2 : ______ "Quit" ENDCASE

Spot the Error

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

Question 1
A CASE Choice
B 1 : OUTPUT "Play"
C 2 : OUTPUT "Quit"
D ENDCASE
Question 2
A INPUT Grade
B CASE OF Grade
C 'A' : OUTPUT "Top"
D 'B' = OUTPUT "Good"
E ENDCASE
Question 3
A CASE OF Day
B 1 : OUTPUT "Mon"
C 2 : OUTPUT "Tue
D 3 : OUTPUT "Wed"
E ENDCASE
Question 4
A DECLARE Choice : INTEGER
B CASE OF Choice
C 1 : OUTPUT "Add"
D "2" : OUTPUT "Delete"
E ENDCASE
Question 5
A INPUT Key
B CASE IF Key
C 'Y' : OUTPUT "Yes"
D 'N' : OUTPUT "No"
E ENDCASE

Answer Key

CASE OF…ENDCASE (8.1b)
Section A: Quick Questions
Q1
B — CASE OF Choice
Q2
A — ENDCASE
Q3
A — 1 : OUTPUT "Start"
Q4
A — One value per line, each with its own statement
Q5
B — Runs the statement beside the value 2
Section B: Match the Pairs
Q1
CASE OF Choice → Starts a CASE statement that compares the variable Choice with a list of values
Q2
ENDCASE → Closes the CASE statement after the last value has been listed
Q3
Each value is written with a colon, then the statement that runs when the variable matches that value → 1 : OUTPUT "Start"
Q4
A CASE statement can test a CHAR variable, with each CHAR value written one per line → CASE OF Grade 'A' : OUTPUT "Top" 'B' : OUTPUT "Good" ENDCASE
Q5
CASE OF Choice 1 : OUTPUT "Start" 2 : OUTPUT "Quit" → ENDCASE is missing, so the CASE statement is never closed. Add ENDCASE after the last value.
Q6
CASE OF Choice 1 OUTPUT "Start" 2 OUTPUT "Quit" ENDCASE → The colon is missing between each value and its statement. It should be 1 : OUTPUT "Start".
Section C: Definitions
Q1
CASE OF Choice — Compares one variable (here Choice) with a list of values, runs the statement beside the matching value, and is closed by ENDCASE.
Section D: Fill in the Blanks
Q1
CASE OF Choice 1 : OUTPUT "Start" ENDCASE
Q2
CASE OF Choice 1 : OUTPUT "Start" ENDCASE
Q3
CASE OF Choice 2 : OUTPUT "Quit" ENDCASE
Q4
CASE OF Grade 'A' : OUTPUT "Top mark" ENDCASE
Q5
CASE OF Choice 2 : OUTPUT "Quit" ENDCASE
Section E: Spot the Error
Q1
A — The CASE line is missing the keyword OF. It should be CASE OF Choice.
Q2
D — A CASE clause needs a colon between the value and the statement, not an equals sign. It should be 'B' : OUTPUT "Good".
Q3
C — The text in the OUTPUT statement is missing its closing quote. It should be OUTPUT "Tue".
Q4
D — Choice is an INTEGER, so each value must be a whole number without quotes. It should be 2 : OUTPUT "Delete".
Q5
B — A CASE statement starts with CASE OF, not CASE IF. IF belongs to selection with a condition. It should be CASE OF Key.