1.10 Subroutines

When we have a block of statements that performs a clearly designated task, we can give the block a life and identity of its own. One way to do this is by organizing the statements of the block into a subroutine. A subroutine has a name. The statements inside the subroutine can be executed as a single group by invoking the name of the subroutine. Thus, if a block of statements is executed several times in a program, we can avoid rewriting the statements, again and again, reducing the length of the program.

A subroutine can be written so that it takes one or more arguments. A subroutine with arguments can be called with different argument values at different times. Thus, the same block of statements can be executed repeatedly such that one execution is slightly different from the next.