Programming concepts - AQASubroutines

Programs are designed using common building blocks, known as programming constructs. These programming constructs form the basis for all programs.

Part ofComputer ScienceComputational thinking and problem solving

Subroutines

Subroutines are smaller, named sections of code that are written within a larger . The purpose of a subroutine is to perform a specific task. This task may need to be done more than once at various points in the main program.

Subroutines are usually small in size, which means they are much easier to write, test and debug. They are also easy for someone else to understand.

As they are written outside of the main program, subroutines can be saved separately as modules and used again in other programs. This saves time because the programmer can use code that has already been written, tested and debugged.

A subroutine may be used repeatedly at various points in the main program and changed by passing in known as parameters. However, the code only has to be written once, resulting in shorter programs.