Defining a procedure with no parameters

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

Defining a procedure with no parameters

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly starts a procedure called ShowMenu that has no parameters?
A PROCEDURE ShowMenu()
B PROCEDURE ShowMenu
2. Which keyword closes a procedure definition?
A ENDPROCEDURE
B END
3. Which procedure is written correctly?
A PROCEDURE SayHello OUTPUT "Hello" ENDPROCEDURE
B PROCEDURE SayHello OUTPUT "Hello"
4. Where should the statements inside a procedure go?
A Indented, between the PROCEDURE line and ENDPROCEDURE
B Before the PROCEDURE line, not indented
5. A procedure has no parameters. Which header is right?
A PROCEDURE PrintLine()
B PROCEDURE PrintLine

Match the Pairs

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

Left columnRight column
1PROCEDURE ShowMenu APROCEDURE ShowMenu OUTPUT "1. Play" OUTPUT "2. Quit" ENDPROCEDURE
2ENDPROCEDURE BPROCEDURE PrintLine
3The statements in the body of a procedure are indented under the PROCEDURE line CENDPROCEDURE is missing, so the procedure is never closed. Add ENDPROCEDURE on the last line.
4A procedure with no parameters is named without brackets after PROCEDURE DBrackets were added although there are no parameters. The header should be PROCEDURE ShowMenu.
5PROCEDURE ShowMenu OUTPUT "1. Play" OUTPUT "2. Quit" EStarts a procedure with no parameters: the keyword PROCEDURE and then the name, with no brackets
6PROCEDURE ShowMenu() FCloses the procedure definition after the indented statements in its body

Definitions

PROCEDURE ShowMenu

Fill in the Blanks

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

1.
_________ ShowMenu OUTPUT "1. Play" ENDPROCEDURE
2.
PROCEDURE Greet OUTPUT "Hello" ____________
3.
PROCEDURE PrintLine ______ "-----" ENDPROCEDURE
4.
PROCEDURE ________ OUTPUT "Menu" ENDPROCEDURE
5.
PROCEDURE AskName _____ Name ENDPROCEDURE

Spot the Error

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

Question 1
A PROCEDURE ShowMenu
B OUTPUT "1. Play"
C OUTPUT "2. Quit"
D ENDFUNCTION
Question 2
A // Greets the player
B Greet PROCEDURE
C OUTPUT "Hi"
D ENDPROCEDURE
Question 3
A PROCEDURE ShowScore
B Score ← 10
C RETURN Score
D ENDPROCEDURE
Question 4
A PROCEDURE PrintBorder
B OUTPUT "*****"
C OUTPUT "*****"
D ENDPROC
Question 5
A // Show the menu
B PROCEDURE ShowMenu()
C OUTPUT "1. Play"
D ENDPROCEDURE

Answer Key

Defining a procedure with no parameters
Section A: Quick Questions
Q1
B — PROCEDURE ShowMenu
Q2
A — ENDPROCEDURE
Q3
A — PROCEDURE SayHello OUTPUT "Hello" ENDPROCEDURE
Q4
A — Indented, between the PROCEDURE line and ENDPROCEDURE
Q5
B — PROCEDURE PrintLine
Section B: Match the Pairs
Q1
PROCEDURE ShowMenu → Starts a procedure with no parameters: the keyword PROCEDURE and then the name, with no brackets
Q2
ENDPROCEDURE → Closes the procedure definition after the indented statements in its body
Q3
The statements in the body of a procedure are indented under the PROCEDURE line → PROCEDURE ShowMenu OUTPUT "1. Play" OUTPUT "2. Quit" ENDPROCEDURE
Q4
A procedure with no parameters is named without brackets after PROCEDURE → PROCEDURE PrintLine
Q5
PROCEDURE ShowMenu OUTPUT "1. Play" OUTPUT "2. Quit" → ENDPROCEDURE is missing, so the procedure is never closed. Add ENDPROCEDURE on the last line.
Q6
PROCEDURE ShowMenu() → Brackets were added although there are no parameters. The header should be PROCEDURE ShowMenu.
Section C: Definitions
Q1
PROCEDURE ShowMenu — Starts a procedure with no parameters: the keyword PROCEDURE, then its name with no brackets. Indented statements follow, and ENDPROCEDURE closes it.
Section D: Fill in the Blanks
Q1
PROCEDURE ShowMenu OUTPUT "1. Play" ENDPROCEDURE
Q2
PROCEDURE Greet OUTPUT "Hello" ENDPROCEDURE
Q3
PROCEDURE PrintLine OUTPUT "-----" ENDPROCEDURE
Q4
PROCEDURE ShowMenu OUTPUT "Menu" ENDPROCEDURE
Q5
PROCEDURE AskName INPUT Name ENDPROCEDURE
Section E: Spot the Error
Q1
D — A procedure must be closed with ENDPROCEDURE. ENDFUNCTION closes a FUNCTION, so the keywords do not match.
Q2
B — The keyword PROCEDURE must come first, followed by the name. It should be PROCEDURE Greet.
Q3
C — A procedure does not return a value, so RETURN does not belong in it. The line should be OUTPUT Score.
Q4
D — The closing keyword is spelled in full: ENDPROCEDURE. ENDPROC is not a keyword.
Q5
B — A procedure with no parameters is written without brackets. It should be PROCEDURE ShowMenu.