Skip to main content

IAR Embedded Workbench for RL78 5.20

EXP-loop-exit

In this section:
Synopsis

An unconditional break, continue, return, or goto within a loop.

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

There is an unconditional break, goto, continue or return in a loop. This means that some iterations of the loop will never be executed. This is most likely not the intended behavior.

Coding standards

This check does not correspond to any coding standard rules.

Code examples

The following code example fails the check and will give a warning:

void example(void) {
  int x = 1;
  int i;

  for (i = 0; i < 10; i++) {
    x = x + 1;
    break;  /* Unexpected loop exit */
  }
}

The following code example passes the check and will not give a warning about this issue:

void example(int a) {
  int x = 1;
  int i;  

  for (i = 0; i < 10; i++) {
    x = x + 1;
    if (x > a) {
      break;  /* loop exit is conditional */
    }
  }
}