Parameters | ||||||||||||||||||||||||||||||
In the previous example we had a procedure which drew a line of 20 dashes :
..which is OK but what if sometimes we wanted lines with 10 dashes and sometimes lines with 40 dashes ...and so on... The way to do this is to pass a parameter to the procedure...
and when we call the procedure we put in brackets the value of the parameter we would like to pass....
for a line of 40 dashes or
for a line of 10 dashes. Suddenly our procedure DrawLine is much more useful! Another important point about subroutines.... 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.
|
||||||||||||||||||||||||||||||