[Solved] While loop running incorrect number of times


You must initialize finished to false if you want to enter the while, and after, when job is done set finished to true to exit the loop

boolean finished = false;
while (!finished) {
//     ↑ ↑ ↑ ↑ ↑ →→→→→→ this means loop while finished == false 
    randomNumber1 = random.nextInt(size);
    randomNumber2 = random.nextInt(size);
    if (puzzlePanel.arrayOfButtons[randomNumber1][randomNumber2].getText().isEmpty()) {
        puzzlePanel.arrayOfButtons[randomNumber1][randomNumber2].setText(puzzle.getSingleLetter(randomNumber1, randomNumber2) + "");
        finished = true;
     }    
 }

1

solved While loop running incorrect number of times