Difference between revisions of "Subroutines - Methods - 2017"
ThomasWard (talk | contribs) (Created page with "A subroutine is a name given to a block of code that can be called by name to perform the operation in the subroutine without having to copy the code it contains. If the subro...") |
ThomasWard (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
A subroutine is a name given to a block of code that can be called by name to perform the operation in the subroutine without having to copy the code it contains. If the subroutine is used to return a value and not just perform an operation, it is known as a function. The subroutine can be passed by a variable parameter if the data type is specified. | A subroutine is a name given to a block of code that can be called by name to perform the operation in the subroutine without having to copy the code it contains. If the subroutine is used to return a value and not just perform an operation, it is known as a function. The subroutine can be passed by a variable parameter if the data type is specified. | ||
+ | <syntaxhighlight lang="csharp" line> | ||
private void CreateNewFox() | private void CreateNewFox() | ||
{ | { | ||
Line 15: | Line 16: | ||
FoxCount++; | FoxCount++; | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | This is an example of a non-function subroutine in the skeleton program. |
Latest revision as of 14:00, 6 February 2017
A subroutine is a name given to a block of code that can be called by name to perform the operation in the subroutine without having to copy the code it contains. If the subroutine is used to return a value and not just perform an operation, it is known as a function. The subroutine can be passed by a variable parameter if the data type is specified.
1 private void CreateNewFox()
2 {
3 int x, y;
4 do
5 {
6 x = Rnd.Next(0, LandscapeSize);
7 y = Rnd.Next(0, LandscapeSize);
8 } while (Landscape[x, y].Fox != null);
9 if (ShowDetail) {
10 Console.WriteLine(" New Fox at (" + x + "," + y + ")");
11 }
12 Landscape[x, y].Fox = new Fox(Variability);
13 FoxCount++;
14 }
This is an example of a non-function subroutine in the skeleton program.