Please enable JavaScript.
Coggle requires JavaScript to display documents.
Procedures and functions :!?: ((There are two types of variable that can…
Procedures and functions :!?:
Procedures
a procedure consists of:
A heading
A declaration part
An action part
They are activated by a call from the main program. When a procedure is called it produces an effect.
Functions
random:
generates a random number
round:
rounds a umber to a certain number of decimal places
Length:
works out the length of a string
A function is activated by a call from the main program. A function returns a single value.
As well as using pre-defined functions we can also write our own functions.
A function consists of:
A heading
A declaration part
An action part
There are two types of variable that can be used in a program:
Local variables
Global variables
Local variables:
Local variables are created when the subroutine is called and are then destroyed when the subroutine terminates.
They cannot be accessed or assigned a value except within that subroutine.
Global Variables:
A global variable can be accessed and altered from any part of the program, even from another script/event so long as it is declared at the very start.
The
scope
means where the variable is visible in the program.
Passing a parameter
by reference
is used when a parameter is needed in a subroutine and its value is going to change in the subroutine when it is passed in.
The subroutine will be passed the original parameter and any changes made in the subroutine will result in a change to the original value(s) held within the parameter.
Passing a parameter
by value
is used when a parameter is needed in a subroutine but its value is not going to change in the subroutine.
The subroutine will be passed a copy of the original parameter, so that the original parameter remains unchanged.
What is a parameter?
A parameter can be either a variable or an array. It can be passed into a sub-routine in one of two ways.
Passed by value
Passed by reference