Hello,
I code in C++.
The rule S878 forbids comma operator in while
loops, but not in for
loops:
The comma operator is tolerated in initializations and increment expressions of for
loops.
Why ?
Hello,
I code in C++.
The rule S878 forbids comma operator in while
loops, but not in for
loops:
The comma operator is tolerated in initializations and increment expressions of for
loops.
Why ?
Hi @Oodini,
The rule forbids comma operators in for
loops only in initialization and increment expressions, not in the condition, which is the only part in a while loop, so they are both treated the same in that regard.
Forbidding comma operators in increments would not be a good rule because that would lead to less readable alternatives and because a typical increment behaves in an easily readable way:
i++, j++
in the increment of a for-loop will increment both i
and j
as one would expect.i>0, j>0
in the condition will not check i
and j
as one would expect.