Subroutines
Introduction / Definition
A subroutine is a named reusable block that performs a task. It may accept parameters and return a result or perform an effect. Subroutines improve modularity and reduce duplication. Functions and procedures are common forms.
Syntax / Structure / Formula
name(parameters) → body → return
Detailed Explanation
A call transfers control to the subroutine and later returns to its caller. Parameters define the information passed into it.
Example
Example: max(7,4) returns 7.
Output / Result
The larger argument is returned.
Important Points / Notes
- Keep responsibilities focused.
- Document inputs and outputs.
Mini Practice Question
What is the main purpose of a subroutine?
CheckpointTest Yourself