Subroutines
Named blocks of code that perform specific tasks and can be called multiple times from different locations in a program. Subroutines (functions, procedures, methods) reduce code duplication and improve maintainability. Subroutines may accept parameters for input and return values for output. Well-designed subroutines have single responsibilities and clear interfaces.
Real World
In Minecraft's codebase, a calculateDamage() subroutine is called whenever any mob attacks, any block explodes, or any player falls — one reusable block instead of duplicating damage logic hundreds of times.
Exam Focus
Clearly distinguish between functions (return a value) and procedures (do not return a value) when asked to define subroutines.
How well did you know this?