samedi 26 décembre 2015

Return with a for loop

The code i am using is below. As far as i am aware the logic of the code is fine but when the return is after the print for the char B then the i within the for loop wont increment. If i remove the return statement then the for loop will increment as i wanted it too, however i need the method to end if the B/W is printed so i need the return to be present. Any help is greatly appreciated i've been trying to work out whats wrong for hours now.

if(currentCodeString.contains("" + currentGuessChar)) {
        for (int i = 0; i < codeLength; i++) {
            System.out.println("" + i);
            //System.out.println(currentGuess[i] + " - " + currentCode[i]);
            if(checkPins(currentGuess[i], currentCode[i])) {
                System.out.print("B");
                return;
            }
        }
        System.out.print("W");
        return;
    }

Aucun commentaire:

Enregistrer un commentaire