Please enable JavaScript.
Coggle requires JavaScript to display documents.
Programming Features (Procedures and Functions (The Benefits (4) The code…
Programming Features
Procedures and Functions
Procedures
Definition: A procedure consists of: a heading, a declaration part, and an action part. They're activated by a call from the main program. When a procedure is called it produces an effect.
Differences: A procedure produces an effect while a function returns a single value; procedures perform a task while functions produce information
Functions
Definition: A function consists of: a heading, a declaration part, and an action part. They're activated by a call from the main program. A function returns a single value.
-
The Benefits
-
-
-
1) Debugging the main program is easier, because the procedures can be tested individually
-
-
Parameter Passing
Passing by Value
Definition: Passing by value is used when a variable's value isn't going to change in the subroutine it's been called for.
The subroutine is given a copy of the original variable, the original remaining unchanged.
Passing by Reference
Definition: Passing by reference is used when a variable's value is going to change when it's called in a subroutine.
The subroutine is given the original variable, and any changes made to it within the subroutine apply to the variable itself.
Arrays are always passed by reference because if we were to pass them by value, the entire array would be copied, including all the valuables. It takes up a lot of space to do this, and so we pass them by reference instead.
A local variable exists within one subroutine, function, or procedure.
Local variables are created when the subroutine is called and are then destroyed when the subroutine terminates.
A local variable exists within one subroutine, function, or procedure.