Parameters | ||||||||||
Parameters are what make subroutines useful. They are a means of passing information to a subroutine Subroutines should be designed to be as 'self-contained' as possible. This means that they should not rely on variables or results from other subroutines - and they do not use variables declared globally if it can be avoided. The interface of a subroutine should only be through its parameters. A well-designed subroutine should be capable of being used in programs other than the one for which it was originally designed. |
||||||||||
Parameter passing...can be
Example 1 (by value): A procedure which draws a line of dashes.
Example 2 (by reference): A procedure which converts a number of days into weeks and days.
|
||||||||||
Exercise | ||||||||||
Question : Why could we not write the ToWeeks procedure as a function? Answer : (click on box to reveal)
|
||||||||||