...
Anchor | ||||
---|---|---|---|---|
|
Noncompliant Code Example (
...
equivalence)
This noncompliant code example may appear to have 5 iterations, but in fact, the loop never terminates.
...
Using the relational operator <=
instead of an inequality equivalence guarantees loop termination.
...
Anchor | ||||
---|---|---|---|---|
|
Noncompliant Code Example (
...
equivalence)
It is also important to ensure termination of loops where the start and end values are variables that might not be properly ordered. The following function assumes that begin < end
; if this is not the case, the loop will never terminate.
...
Again, using a relational operator instead of inequality equivalence guarantees loop termination. If begin >= end
the loop never executes its body.
...