Difference between revisions of "Subroutines - Methods - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
 
Line 17: Line 17:
 
     }
 
     }
 
</syntaxhighlight>
 
</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.