我目前正在尝试使用变量“breakOK”进行非常简单的检查,以跳出 for 循环。如果满足我的拼图矩阵中的当前值设置为 46 的条件,则调用一个函数并将 breakOK 设置为 1,以便我们可以跳出循环。但是,在下面代码的 if 语句中使用 breakOK 时出现以下错误:
sudoku.cc:482:13: error: 'breakOK' was not declared in this scope
sudoku.cc:485:11: error: 'breakOK' was not declared in this scope
这真的很奇怪,因为我以相同的方式声明 Guess,并且稍后在我的代码中使用它时不会出现范围错误!此外,当我在循环中设置 breakOK 等于 1 时,编译器不会抱怨。任何帮助将不胜感激,我已经坚持了太久了!
int Guess = 0; // will be set to a value if a guess is ok
int breakOk = 0; // will be set to 1 if breaking out of loops is necessary
for (int row = 0; row < 9; row++)
{
for (int col = 0; col < 9; col++)
{
if (puzzle.matrix[row][col].currentValue == 46)
{
Guess = guessValues(row, col, puzzle, tried, allowed);
breakOk = 1;
}
if (Guess != 0)
{
tried[row][col].tries.push_back(Guess);
//puzzle.decide(row, col, Guess);
puzzle.matrix[row][col].currentValue = Guess;
}
if (breakOK == 1) // line 482
break;
}
if (breakOK == 1) // line 485
break;
}