Please enable JavaScript.
Coggle requires JavaScript to display documents.
Computing Science Summary - Coggle Diagram
Computing Science Summary
Procedures and Functions
Procedures
They are activated by a call from the main program. When a procedure is called it produces an effect.
Consist of:
A heading
A declaration
An action part
Procedure code can be saved and re-used in future projects by creating a module library.
Functions
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
You can get pre-defined functions such as:
Random - Generates a random number
Round - Rounds a number to a certain decimal place
Length - Works out the length of a string
we can also write our own functions.
A function is activated by a call from the main program. A function returns a single value.
Benefits
The repetition of lines of code is avoided.
Testing of the procedure code can take place in isolation from the main program.
Debugging of the main program is simplified as each procedure can be individually tested.
Formal and Actual Parameters
A formal parameter is used as a placeholder within a subprogram for the values received or sent to the main program’s actual parameters.
An actual parameter is the actual value that is passed into the procedure.
Reference and Value
Value is a copy of the parameter that cant be changed
Reference is the parameter that can be changed
We use reference when passing an array regardless of whether or not it is changing to save space
Local and Global
Local is the variable that is confined to its own chunk of code unlike Global
Global is the variable that is used through the whole code