The program change when swapping the condition in C++

Yesterday, when I did a coding problems, I met the errors in the code:

    while (count <= column * row) {
    if (matrix(rowOne + 1)(columnOne) == count && rowOne + 1 >= 0 && rowOne + 1 < row) {
        count++;
        rowOne++;
    } else if (matrix(rowOne - 1)(columnOne) == count && rowOne - 1 >= 0 && rowOne - 1 < row) {
        count++;
        rowOne--;
    } else if (matrix(rowOne)(columnOne - 1) == count && columnOne - 1 >= 0 && columnOne - 1 < column) {
        count++;
        columnOne--;
    } else if (matrix(rowOne)(columnOne + 1) == count && columnOne + 1 >= 0 && columnOne + 1 < column) {
        count++;
        columnOne++;
    } else {
        return false;
    }
}
return true;

I have already checked the code above this code, they were right but in this code, if I changed in each if and else if line, for example the line:

      if (matrix(rowOne + 1)(columnOne) == count && rowOne + 1 >= 0 && rowOne + 1 < row)

I changed it to:

      if (rowOne + 1 >= 0 && rowOne + 1 < row && matrix(rowOne + 1)(columnOne) == count)

The program was working but I didn’t know why, can somebody help me?, Thank you!