dimanche 5 mars 2017

Code running through a false if statement

if(adjacentSqRow>=0 && adjacentSqCol>=0){
    if(board[adjacentSqRow][adjacentSqCol]!=EMPTY){
      return true;
    }
}

I have this nest of "if" statements inside of a "for" loop. The "if" statement is a way to make sure that no negative values are allowed through to be tested in an array. The problem that I have is that in the first iteration of the "for" loop the variables adjacentSqRow and adjacentSqCol and both an int at -1. For some reason the "if" statement is still allowing them through and causing an ArrayOutOfBoundsException here. Not sure whats up with this though.

Aucun commentaire:

Enregistrer un commentaire