Which statement is used to end a subroutine and optionally return a value?

Prepare for the IGCSE Algorithms and Pseudocode Exam. Study with comprehensive questions covering key algorithms and pseudocode techniques. Access hints and explanations to gear up for your exam success!

Multiple Choice

Which statement is used to end a subroutine and optionally return a value?

Explanation:
Returning from a subroutine with a value is done using the return statement. It ends the subroutine’s execution and hands a value back to the code that called it. If you specify a value after return (like return x), that value becomes the subroutine’s result. If you omit a value, the subroutine ends without returning data, which is allowed in some languages as a void return. The other options don’t fit this specific purpose: break is used to exit loops or switch blocks, not to finish a subroutine; continue moves to the next iteration of a loop; and exit the program stops the entire program, not just one subroutine.

Returning from a subroutine with a value is done using the return statement. It ends the subroutine’s execution and hands a value back to the code that called it. If you specify a value after return (like return x), that value becomes the subroutine’s result. If you omit a value, the subroutine ends without returning data, which is allowed in some languages as a void return.

The other options don’t fit this specific purpose: break is used to exit loops or switch blocks, not to finish a subroutine; continue moves to the next iteration of a loop; and exit the program stops the entire program, not just one subroutine.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy