Subroutines - Functions

From TRCCompSci - AQA Computer Science
Revision as of 23:11, 15 December 2016 by QuantumFluctuator (talk | contribs)
Jump to: navigation, search

A set of instructions designed to perform a frequently used operation within a program. This makes it easy to repeat code. A subroutine must be contained in a class, and should the class not be the same as the one calling it, it should be referred to directly or by instantiation.

Example

File:Sub.PNG

Every time greeting() is written the program runs the greeting subroutine.

Passing Variables

Variables may need to be passed across subroutines in order for them to execute correctly.

Example

File:Passing variables.png

Data Type Subroutines

A subroutine may need to return a variable type to assign to a variable when called. This can be done using any data type.

Example

File:Data passing.png