Subroutine: Difference between revisions
From Coderwiki
More actions
new: info, parameters, types |
replace link to Return with Function return |
||
| Line 10: | Line 10: | ||
== Types of subroutines == | == Types of subroutines == | ||
* [[Function]] - a subroutine which '''does''' [[return]] a [[value]]. | * [[Function]] - a subroutine which '''does''' [[Function return|return]] a [[value]]. | ||
* [[Procedure]] - a subroutine which '''does not''' [[Function return|return]] a [[value]]. | * [[Procedure]] - a subroutine which '''does not''' [[Function return|return]] a [[value]]. | ||
Latest revision as of 21:36, 15 August 2025
A subroutine is a code block in a separate part of the source code.
This code block can be called, or 'invoked', and calling the subroutine will run the code in the code block.
Parameters
edit edit sourceSubroutines can take in parameters. These parameters give the subroutine more information about how to run and what values to act upon.
For example, a function addOne which simply returns the integer one above the value of the parameter we pass in, could take in an integer called num as a parameter.