You are on page 1of 1

Functions and Sub Routines:-

A function takes parameters, works locally and does not alter any value or work with any value outside
its scope (high cohesion). It also returns some value.
A subroutine works directly with the values of the caller or code segment which invoked it and does not
return values (low cohesion), i.e. branching some code to some other code in order to do some
processing and come back.
Parameters are used in functions and subroutines. They pass data to be used with the
function/parameter. For use with our two examples:
Function Parameters) The Subtotal passed to the function is a parameter.
Subroutine Parameters) The player's amount of gold could be sent to the
subroutine so the shop
knows how much money the player can spend.
There are two different ways to send parameters, by the value or by reference. By Value means
that the function can not actually change the data outside of the function, but can use it's data to
manipulate other data that is returned. By Value is like making a carbon copy of a paper, and
editing the carbon copy. By Reference sends the actual argument (parameter) to the
function/subroutine, which is like editing the original copy of the paper. By Value is wrote as
ByVal and By Reference is wrote as ByRef.
Conclusion:-
Subroutines do not return any values, while functions return values. Subroutines are also allowed
to change values of the parameters while functions are supposed to maintain.

You might also like