What is the reason behind disallowing the comma operator in the
for-condition
of a for statement?
It's allowed in C.
It's allowed in the for-initializer and the for-iterator, but not the
for-condition; that seems arbitrary.
Because it would be confusing and useless.
Neither the initializer nor the iterator are dependent on the expression
value, so having comma-separated items doesn't matter. But there's no
context-obvious solution for which expression in a list of comma-separated
items should be the _actual_ conditional used for the condition (you have
to remember the arbitrary and forgettable rule), nor is there actually any
practical reason to allow it (the only reason to even use that "feature"
would be to put something with side-effects in there, which is just asking
for a maintenance headache).
For what it's worth, I'm not even sure it's always allowed in C. I don't
have a specification handy, but the MSDN documentation for Microsoft's
compiler says that commas are allowed only in the initializer and
iterator, not the condition. The Xcode compiler on my Mac, which is based
on gcc, allows it. So it may be one of those many things in the C/C++
specification that is implementation-dependent.
Anyway, the bottom line is that I can see lots of good reasons for C# to
_not_ allow that, and no good reason for it to be allowed.
Pete