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...")
(No difference)

Revision as of 14:57, 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.

private void CreateNewFox()

   {
     int x, y;
     do
     {
       x = Rnd.Next(0, LandscapeSize);
       y = Rnd.Next(0, LandscapeSize);
     } while (Landscape[x, y].Fox != null);
     if (ShowDetail) {
       Console.WriteLine("  New Fox at (" + x + "," + y + ")");
     }
     Landscape[x, y].Fox = new Fox(Variability);
     FoxCount++;
   }