Subroutines & Their Advantages Flashcards
All 3 cards in this deck
Give two advantages of using subroutines in a program.
Any two, e.g.: the code is written once and called whenever it is needed instead of being repeated, so the program is shorter; a change or fix only has to be made in one place; a subroutine can be reused in other programs.
What is a subroutine?
A named 'out of line' block of code that is executed (called) by writing its name in a program statement. Functions and procedures are both subroutines.
What happens when a subroutine is called?
The program runs the subroutine's code, then returns to the point where the subroutine was called and carries on from there, using any value the subroutine returned.