Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2012-Rule-14.2

In this section:
Synopsis

(Required) A for loop shall be well-formed.

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

A malformed for loop was found.

Coding standards
MISRA C:2012 Rule-14.2

(Required) A for loop shall be well-formed

Code examples

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

int main(void) {
  int i;
  /* i is incremented inside the loop body */
  for (i = 0; i < 10; i++) {
    i = i + 1; 
  }
  return 0;
}

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

int main(void) {
  int i;
  int x = 0;    
  for (i = 0; i < 10; i++) {
    x = i + 1;
  }
  return 0;
}