while (int grade = (std::cin >> grade, grade)) { /**/ }
- The condition inside
while
declares a variable and it becomes instantly visible in thewhile
scope - The second operand of assignment evaluates the expression which contains comma operator (which guarantees order of evaluation)
- The comma's left operand yields error-status from
cin
and discards it, as a side effect,grade
gets changed - Comma operator returns right hand side expression, that becomes the value of the variable
Is this legit code? I'm new to C++. Can you please correct my thought process.