Difference between revisions of "Subroutines - Methods - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(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...")
 
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>

Revision as of 14:58, 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     }