jeudi 7 novembre 2019

How do I return from an if statement inside a method?

I am trying to return the booleans inside my if statement. I am getting an error that says "the method must return result type boolean" and I am unsure how to make it return while using the for loop and if statement I have set up. For reference, the loop is checking whether or not all values in the double boolean array are equal to true, if they are, it will return true. If not, it should return false.

boolean isDark() {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (gameField[i][j] == true) {
                    return true;
                }
                else {
                    return false;
                }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire