Difference between revisions of "Subroutines - Functions"
Daddy Scarce (talk | contribs) m |
|||
Line 1: | Line 1: | ||
− | + | 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. | |
− | A set of instructions designed to perform a frequently used operation within a program. This makes it easy to repeat code. | ||
− | + | <h3>Example</h3> | |
[[File:Sub.PNG]] | [[File:Sub.PNG]] | ||
Every time greeting() is written the program runs the greeting subroutine. | Every time greeting() is written the program runs the greeting subroutine. | ||
+ | |||
+ | <h2>Passing Variables</h2> | ||
+ | Variables may need to be passed across subroutines in order for them to execute correctly.<br /> | ||
+ | <h3>Example</h3> | ||
+ | [[File:passing variables.png]] | ||
+ | |||
+ | <h2>Data Type Subroutines</h2> | ||
+ | A subroutine may need to return a variable type to assign to a variable when called. This can be done using any data type.<br /> | ||
+ | <h3>Example</h3> | ||
+ | [[File:data passing.png]] |
Revision as of 22:11, 15 December 2016
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
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
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.