What do you call a block of code that you can call repeatedly and that returns a value?

Prepare for the CodeHS AP Computer Science Principles Exam with multiple choice questions, detailed explanations, and helpful hints. Boost your confidence and get ready for your exam!

Multiple Choice

What do you call a block of code that you can call repeatedly and that returns a value?

Explanation:
A function is a block of code you can call repeatedly and that returns a value. You define it once, and you can reuse it with different inputs to get consistent results. The return statement sends a value back to the place where the function was called, which is what makes the function capable of contributing a value to the rest of the program rather than just performing actions. A parameter is part of the function's interface—the variable in the function definition that receives the input when you call the function. It’s not the reusable block itself, just the way you supply data to it. A loop, including a for loop, focuses on repeating a set of instructions. It may be used inside a function, but by itself a loop isn’t the thing you call to obtain a value back from a single operation. The function is the construct that provides a value to the caller after performing computations.

A function is a block of code you can call repeatedly and that returns a value. You define it once, and you can reuse it with different inputs to get consistent results. The return statement sends a value back to the place where the function was called, which is what makes the function capable of contributing a value to the rest of the program rather than just performing actions.

A parameter is part of the function's interface—the variable in the function definition that receives the input when you call the function. It’s not the reusable block itself, just the way you supply data to it.

A loop, including a for loop, focuses on repeating a set of instructions. It may be used inside a function, but by itself a loop isn’t the thing you call to obtain a value back from a single operation. The function is the construct that provides a value to the caller after performing computations.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy