...
| Code Block | ||
|---|---|---|
| ||
for (i = 1; i <= 10; i += 2) {
// ...
}
|
...
Noncompliant Code Example
EX1: Numerical comparison operators do not ensure loop termination when comparing with Integer.MAX_VALUE or Integer.MIN_VALUE.
| Code Block | ||
|---|---|---|
| ||
for (i = 1; i <= Integer.MAX_VALUE; i += 2) {
// ...
}
|
Compliant Solution
It is not sufficient to compare with Integer.MAX_VALUE - 1 when the loop counter is more than 1. To be safe, ensure that the comparison is carried out with (Integer.MAX_VALUE - counter's value).
...