寻找解决方案如何在正确的地方退出循环

时间:2019-06-07 06:11:50

标签: c# robotics

好的,所以我首先要找到三个freePosition,一个是sortedSystem.BooleanCellSystem [row] [column],然后返回并更改该行,我的问题是我应该在哪里放置{break;},所以我可以拥有3个freePosition与不同的行。谢谢:)

public void FindingFreeCells(SortingSystem sortedSystem, int number)
{
  int freePositions = 0;
  double tempCoef = 0;

  for (int row = 0; row < sortedSystem.BooleanCellSystem.Length; row++)
  {
    for (int column = 0; column < sortedSystem.BooleanCellSystem[row].Length; column++)
    {
      if (sortedSystem.BooleanCellSystem[row][column] != true)
      {
        for (int n = column; n < number; n++)
        {
          if (sortedSystem.BooleanCellSystem[row][column] == true)
          {
            break;
          }
          for (int k = 1; k < 3; k++)
          {
            if (sortedSystem.BooleanCellSystem[row][column + k] != true)
            {
              tempCoef += 5;
            }
          }
          if (n == number - 1)
          {
            freePositions++;
            AvailableCell temp = new AvailableCell();
            temp.FirstRow = row;
            temp.FirstColumn = column;
            temp.CellsRequired = number;
            temp.PriorityCoeff = row + column + tempCoef;
            AvailableCellsList.Add(temp);
          }
        }
      }               
    }
  }
}

0 个答案:

没有答案