The function is suposed to sort the highscore board in the game according to time.
public void sort()
{
boolean unsorted = true;
int i;
for ( ; unsorted; i < this.inputArray.length - 1)
{
unsorted = false;
i = 0; continue;
if (Integer.parseInt(this.inputArray[i][1]) <= Integer.parseInt(this.inputArray[(i + 1)][1]))
{
int tempTime = Integer.parseInt(this.inputArray[i][1]);
String tempName = this.inputArray[i][0];
this.inputArray[i][1] = this.inputArray[(i + 1)][1];
this.inputArray[i][0] = this.inputArray[(i + 1)][0];
this.inputArray[(i + 1)][1] = String.valueOf(tempTime);
this.inputArray[(i + 1)][0] = String.valueOf(tempName);
unsorted = true;
}
i++;
}
}
The problem is, that IDE throws a "not a statement" error at 'for' loop, and "unreachable statement" error on 'if'.
Can anyone help?
The first error is because
is not something you can execute - that is, it's not a statement. But the third part in the brackets of a
for
loop is the statement which will be executed at the end of each iteration of the loop.The second error is because
means start the loop again, with the next iteration. Which means that everything after the
continue
is dead code that can never be reached. The compiler is trying to protect you from what can only be a mistake.