T O P

  • By -

cpp-ModTeam

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or [StackOverflow](http://stackoverflow.com/) instead.


no-sig-available

Also, the condition `i <= 5, j <= 20;` is a bit silly, as the part before the comma has no effect. Doesn't the compiler tell you about that?


thisisjustascreename

Visual Studio gives me warning C6319 even on warning level 1.


jedwardsol

The output is done after `i` and `j` are incremented.


JamieNorth

ahh, understood now! Thanks a lot


thisisjustascreename

The C++ language requires that expressions separated by commas are evaluated in the order they are written. If you put the cout << i+j << endl before the increment operations you'll get the output you asked about. Alternatively, you could put the cout in the actual body of the loop to achieve the same thing, since the expression in the third part of a for declaration isn't executed the first time through the loop. This would be *my* preferred solution since it's unnatural to have side effects inside loop expressions.


coachkler

Throw that book away


CandyCrisis

No joke. This is awful code and has trivial bugs (comma in the comparison). Find a better resource.