continue语句的备选方案

continue语句的备选方案,c,continue,C,Continue,我正在寻找替换此函数中continue语句的方法。houserules声明它们不能被使用,但是我很难实现一个不会导致其余代码错误运行的替换 bool neighCheck (int i, int j, int a[][COLLENGTH]) { bool neighbourOnFire; int x, y, neighX, neighY, curreNeigh; /* Bool set up to change after neighbours looped*/ nei

我正在寻找替换此函数中continue语句的方法。houserules声明它们不能被使用,但是我很难实现一个不会导致其余代码错误运行的替换

bool neighCheck (int i, int j, int a[][COLLENGTH])
{
   bool neighbourOnFire;
   int x, y, neighX, neighY, curreNeigh;

   /* Bool set up to change after neighbours looped*/
   neighbourOnFire = false;
   /* The neighbours -looping from -1 -> 1 to get index of each neighbour*/
   for (x = -1; x < 2; x++) {
      for (y = -1; y < 2; y++) {
         /* Disregards current (middle) cell*/
         if ((x == 0) && (y == 0)) {
            continue;
         }
         /* Get indexes of the neighbour we're looking at */
         neighX = i + x;
         neighY = j + y;
         /* Checks for edges*/
         if (neighX >= 0 && neighY >= 0 && neighX < ROWLENGTH
            && neighY < COLLENGTH) {
            /* Get the neighbour using the indexes above */
            curreNeigh = a[neighX][neighY];
            /* Test to see if the neighbour is burning */
            if (curreNeigh == fire) {
               neighbourOnFire = true;
               continue;
            }
         }
      }
   }
   return neighbourOnFire;
}
bool neighCheck(inti,intj,inta[][COLLENGTH])
{
布尔邻里森林;
整数x,y,neighX,neighY,curreNeigh;
/*波尔在邻居们循环后开始改变*/
neighbourOnFire=false;
/*邻居-从-1->1循环以获取每个邻居的索引*/
对于(x=-1;x<2;x++){
对于(y=-1;y<2;y++){
/*忽略当前(中间)单元格*/
如果((x==0)和&(y==0)){
继续;
}
/*获取我们正在查看的邻居的索引*/
neighX=i+x;
neighY=j+y;
/*检查边缘*/
如果(neighX>=0&&neighY>=0&&neighX
第一个
继续if
语句中来替换code>

第二步
继续
可以简单地删除,因为之后没有要执行的代码

bool neighCheck (int i, int j, int a[][COLLENGTH])
{
   bool neighbourOnFire;
   int x, y, neighX, neighY, curreNeigh;

   /* Bool set up to change after neighbours looped*/
   neighbourOnFire = false;
   /* The neighbours -looping from -1 -> 1 to get index of each neighbour*/
   for (x = -1; x < 2; x++) {
      for (y = -1; y < 2; y++) {
         /* Disregards current (middle) cell*/
         if (!((x == 0) && (y == 0))) {
            /* Get indexes of the neighbour we're looking at */
            neighX = i + x;
            neighY = j + y;
            /* Checks for edges*/
            if (neighX >= 0 && neighY >= 0 && neighX < ROWLENGTH
               && neighY < COLLENGTH) {
               /* Get the neighbour using the indexes above */
               curreNeigh = a[neighX][neighY];
               /* Test to see if the neighbour is burning */
               if (curreNeigh == fire) {
                  neighbourOnFire = true;
               }
            }
         }
      }
   }
   return neighbourOnFire;
}
bool neighCheck(inti,intj,inta[][COLLENGTH])
{
布尔邻里森林;
整数x,y,neighX,neighY,curreNeigh;
/*波尔在邻居们循环后开始改变*/
neighbourOnFire=false;
/*邻居-从-1->1循环以获取每个邻居的索引*/
对于(x=-1;x<2;x++){
对于(y=-1;y<2;y++){
/*忽略当前(中间)单元格*/
如果(!((x==0)和&(y==0))){
/*获取我们正在查看的邻居的索引*/
neighX=i+x;
neighY=j+y;
/*检查边缘*/
如果(neighX>=0&&neighY>=0&&neighX
如果((x!=0)| |(y!=0))
和另一个代码块,为什么不
呢?第二个
continue
是不必要的,因为它是最后一个语句。可以使用
goto
?;-)<代码>邻居配置=真
可以替换为
返回true在这种情况下。