return keyword

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

return keyword

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does return send a value back from a function to where it was called?
A False
B True
2. Does code after a return statement inside a function still run?
A False
B True
3. Should the return keyword be followed by the value being sent back?
A True
B False
4. Can a returned value be stored in a variable when the function is called?
A True
B False
5. Is RETURN written in uppercase in VCAA pseudocode?
A True
B False

Match the Pairs

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

Left columnRight column
1return result Areturn should not use parentheses around its value
2return num * num Boutput ← addNumbers(3, 4)
3A keyword that sends a value back and ends a function's execution Creturn
4Storing the value sent back by a function in a variable DThe keyword should be written in lowercase as return, not RETURN
5define isEven(num) IF num MOD 2 = 0 THEN RETURN TRUE END IF end function ECalculates a value and sends it back immediately
6define getMax(a, b) IF a > b THEN return a ELSE return(b) END IF end function FSends the value stored in result back from the function

Definitions

return

Fill in the Blanks

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

1.
______ result
2.
define square(num) ______ num * num end function
3.
define isPositive(num) IF num > 0 THEN ______ TRUE END IF end function
4.
define multiply(x, y) ______ x * y end function
5.
output ← addNumbers(3, 4) __ this stores the returned value

Spot the Error

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

Question 1
A define addNumbers(a, b)
B result ← a + b
C give result
D end function
Question 2
A define isEven(num)
B IF num MOD 2 = 0 THEN
C RETURN TRUE
D END IF
E end function
Question 3
A define multiply(x, y)
B return x * y
C end function
D output ← multiply(2, 3)
Question 4
A define getMax(a, b)
B IF a > b THEN
C return a
D ELSE
E return(b)
F END IF
Question 5
A define greet(name)
B return "Hello, " + name
C end function
D message ← greet("Sam")

Answer Key

return keyword
Section A: Quick Questions
Q1
B — True
Q2
A — False
Q3
A — True
Q4
A — True
Q5
B — False
Section B: Match the Pairs
Q1
return result → Sends the value stored in result back from the function
Q2
return num * num → Calculates a value and sends it back immediately
Q3
A keyword that sends a value back and ends a function's execution → return
Q4
Storing the value sent back by a function in a variable → output ← addNumbers(3, 4)
Q5
define isEven(num) IF num MOD 2 = 0 THEN RETURN TRUE END IF end function → The keyword should be written in lowercase as return, not RETURN
Q6
define getMax(a, b) IF a > b THEN return a ELSE return(b) END IF end function → return should not use parentheses around its value
Section C: Definitions
Q1
return — A keyword that sends a value back from a function to where it was called, ending the function's execution at that point
Section D: Fill in the Blanks
Q1
return result
Q2
define square(num) return num * num end function
Q3
define isPositive(num) IF num > 0 THEN return TRUE END IF end function
Q4
define multiply(x, y) return x * y end function
Q5
output ← addNumbers(3, 4) // this stores the returned value
Section E: Spot the Error
Q1
C — The keyword to send a value back from a function is return, not give.
Q2
C — The keyword should be written in lowercase as return, not RETURN.
Q3
D — There is no incorrect line here — all lines follow correct return keyword syntax.
Q4
E — return should not use parentheses around its value; it should be written as return b.
Q5
D — There is no incorrect line here — all lines follow correct return keyword syntax.