Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: NCCE->CS

...

Code Block
bgColor#FFcccc
langc
 do { /* ... */ } while (foo(), x = y);

The same result can be obtained using the for statement, which is specifically designed to evaluate an expression on each iteration of the loop, just before performing the test in its controlling expression:

Code Block
 for (; x; foo(), x = y) { /* ... */ }

Compliant Solution (Unintentional Assignment)

...

Code Block
bgColor#ccccff
langc
do { /* ... */ } while (foo(), (x = y) != 0);

Compliant Solution (for statement)

The same result can be obtained using the for statement, which is specifically designed to evaluate an expression on each iteration of the loop, just before performing the test in its controlling expression. Remember that its controlling expression is the second operand, where the assignment occurs in its third operand:

Code Block
bgColor#ccccff
langc
 for (; x; foo(), x = y) { /* ... */ }

Noncompliant Code Example

...