Difference between revisions of "Repetition - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "Repeats a section of code until a set of parameters are met (or one parameter).<br /> From Warren; Line 16: <syntaxhighlight lang="csharp"> for (int r = 0; r < RabbitCo...")
 
Line 7: Line 7:
 
       }
 
       }
 
</syntaxhighlight> <br />
 
</syntaxhighlight> <br />
The for loop creates a new entry in the Rabbits array, using the Rabbit class, until the variable r reaches the RabbitCount variable.<br />
+
The for loop creates a new entry in the Rabbits array, using the Rabbit class, until the variable r reaches the RabbitCount variable.<br /><br />
 +
From Simulation; Line 88:
 +
<syntaxhighlight lang="csharp">
 +
for (int x = 0; x < LandscapeSize; x++)
 +
      {
 +
        for (int y = 0; y < LandscapeSize; y++)
 +
        {
 +
          if (Landscape[x, y].Warren != null)
 +
          {
 +
            if (ShowDetail)
 +
            {
 +
              Console.WriteLine("Warren at (" + x + "," + y + "):");
 +
              Console.Write("  Period Start: ");
 +
              Landscape[x, y].Warren.Inspect();
 +
            }
 +
            if (FoxCount > 0)
 +
            {
 +
              FoxesEatRabbitsInWarren(x, y);
 +
            }
 +
            if (Landscape[x, y].Warren.NeedToCreateNewWarren())
 +
            {
 +
              CreateNewWarren();
 +
            }
 +
            Landscape[x, y].Warren.AdvanceGeneration(ShowDetail);
 +
            if (ShowDetail)
 +
            {
 +
              Console.Write("  Period End: ");
 +
              Landscape[x, y].Warren.Inspect();
 +
              Console.ReadKey();
 +
            }
 +
            if (Landscape[x, y].Warren.WarrenHasDiedOut())
 +
            {
 +
              Landscape[x, y].Warren = null;
 +
              WarrenCount--;
 +
            }
 +
          }
 +
        }
 +
      }
 +
</syntaxhighlight>

Revision as of 12:38, 7 February 2017

Repeats a section of code until a set of parameters are met (or one parameter).
From Warren; Line 16:

 
      for (int r = 0; r < RabbitCount; r++)
      {
        Rabbits[r] = new Rabbit(Variability);
      }


The for loop creates a new entry in the Rabbits array, using the Rabbit class, until the variable r reaches the RabbitCount variable.

From Simulation; Line 88:

for (int x = 0; x < LandscapeSize; x++)
      {
        for (int y = 0; y < LandscapeSize; y++)
        {
          if (Landscape[x, y].Warren != null)
          {
            if (ShowDetail)
            {
              Console.WriteLine("Warren at (" + x + "," + y + "):");
              Console.Write("  Period Start: ");
              Landscape[x, y].Warren.Inspect();
            }
            if (FoxCount > 0)
            {
              FoxesEatRabbitsInWarren(x, y);
            }
            if (Landscape[x, y].Warren.NeedToCreateNewWarren())
            {
              CreateNewWarren();
            }
            Landscape[x, y].Warren.AdvanceGeneration(ShowDetail);
            if (ShowDetail)
            {
              Console.Write("  Period End: ");
              Landscape[x, y].Warren.Inspect();
              Console.ReadKey();
            }
            if (Landscape[x, y].Warren.WarrenHasDiedOut())
            {
              Landscape[x, y].Warren = null;
              WarrenCount--;
            }
          }
        }
      }