...
Code Block |
---|
|
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 |
---|
|
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 |
---|
|
for (; x; foo(), x = y) { /* ... */ } |
Noncompliant Code Example
...