Why is this an infinite loop?

Its a sudoku solver, when I use cout for the int k it displays 0 through 8 endlessly. But I cannot make sense as to why it is an endless loop

void solveBoard(int board[][9], bool possible[])
{
bool complete = false;

while (complete == false)
{
int numPossible = 0;
complete = true;

for (int j = 0; j < 9; j++) // this one runs through the row
{

for (int k = 0; k < 9; k++) //this one does the column
{
cout << k;
if (board[j][k] == 0)
complete = false;
computeValues(board, possible, j, k);

for (int i = 0; i < 9; i++) // this runs through a bool indicating if each
//i is true (possible) or false
if (possible[i] == true)
numPossible++;
if (numPossible == 1)
board[j][k] = possible[0];
}
}
}

return;
}
Last edited on
why do you do this?

1
2
if (board[j][k] == 0)
complete = false;


Is that keeping you in the while loop?


Every single time I run through the while loop I reset complete to true, and it only gets set to false (I think) when I find a 0 in the sudoku puzzle, meaning its not complete yet.
I just realized, in the line before return, I was setting board[j][k] to whatever was in possible[0]. Possible is a bool, I want numbers in the board not bools. So I reset it to possible[i] and im still finding myself in an infinite loop.
possible[i] is also a bool. You need to assign board[j][k] the value i+1 for which possible[i] is true, if I understand what you're doing.
Last edited on
Topic archived. No new replies allowed.