By defining functions, procedures, and formulas in subroutines, programs become faster to create, easier to write, and require less time to test. A subroutine used for one device can also be adapted for other devices.
For example, if a specific operation is performed five different times during one pass of the program, you have two programming options.
- The first option is to duplicate the code in five different places in the program.
- This option adds five times as much program code.
- When making a change to one segment, you must remember to change all occurrences of that code.
- The second option is to use a subroutine. Every time the operation is needed, program control is transferred to the subroutine.
- This option reduces the amount of mainline program code.
- When making a change, there is only one section of code to change.