An infinite loop will never end while the program runs, meaning you have to kill the program to get out of the loop. Every loop should have an end
condition, whether by meeting the loop’s termination condition or via a break
statement.
Noncompliant code example
for (;;) { // Noncompliant; end condition omitted
// ...
}
int j;
while (true) { // Noncompliant; end condition omitted
j++;
}
int k;
boolean b = true;
while (b) { // Noncompliant; b never written to in loop
k++;
}
Compliant solution
int j;
while (true) { // reachable end condition added
j++;
if (j == Integer.MIN_VALUE) { // true at Integer.MAX_VALUE +1
break;
}
}
int k;
boolean b = true;
while (b) {
k++;
b = k < Integer.MAX_VALUE;
}