Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor
nce_inequality_multistep
nce_inequality_multistep

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
nce_inequality
nce_inequality

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.

...