An infinite loop is one that will never end while the program is running, I.E. you have to kill the program to get out of the loop. Whether it is
by meeting the loop's end condition or via a break, every loop should have an end condition.
for (;;) { // Noncompliant; end condition omitted
// ...
}
for (int i = 0; i < 10; i--) { // Noncompliant; end condition but unreachable
//...
}
int j;
while (true) { // Noncompliant; end condition omitted
j++;
}
int k;
boolean b = true;
while (b) { // Noncompliant; b never written to in loop
k++;
}
for (int i = 0; i < 10; i++) { // end condition now reachable
//...
}
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;
}