次のコードがあります。
boolean[] usedInts = {false, false, false, false, false, false, false, false, false};
for(int i = 0; i <= 8; i++) {
JLabel square = squares[i];
// Declare coordinate
Coordinate coordinate = null;
boolean keepGoing = true;
while (keepGoing) {
// Get random number
int rand = generateRandom();
if (usedInts[rand]) {
keepGoing = true;
} else {
// Save that we used it
usedInts[rand] = true;
keepGoing = false;
}
// Initialize coordinate
coordinate = coordinates[rand];
}
// Set square coordinates
square.setLocation(coordinate.getX(), coordinate.getY());
// Set used to true
}
問題は、while
ループが無限で、else
パーツが 8 回しか実行されないことです。ここで何が起こっているのですか?