while (int grade = (std::cin >> grade, grade)) { /**/ }
- The condition inside
whiledeclares a variable and it becomes instantly visible in thewhilescope - 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
cinand discards it, as a side effect,gradegets 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.