| Feature | Function | Procedure |
|---|---|---|
| Return Value | Always returns a value to the caller | Does not return a value |
| Usage | Used in assignments or expressions (e.g., ) | Used as a standalone instruction |
| Purpose | Typically used for calculations or data retrieval | Typically used for actions (e.g., printing, saving) |
Check the Return Type: When asked to write a subprogram, identify if the task requires a result to be used later (Function) or just an action to be performed (Procedure).
Parameter Matching: Ensure that the number and data types of arguments passed during a call exactly match the parameters defined in the subprogram header.
Trace the Flow: In 'trace table' questions, remember that the program 'jumps' to the subprogram code and then 'jumps back' to the exact point where it was called once finished.
Naming Conventions: Use descriptive verbs for procedures (e.g., printReport) and nouns or descriptive results for functions (e.g., calculateTotal) to improve clarity.
Scope Errors: A common mistake is attempting to use a variable defined inside a subprogram (local variable) in the main program, which results in an 'undefined' error.
Missing Return Statements: Forgetting the return keyword in a function will often result in the function returning null or None, breaking subsequent calculations.
Argument Order: Passing arguments in the wrong sequence (e.g., passing age where height is expected) will not always cause a crash but will lead to logical errors in the output.