R
Roman Töngi
for (int i = 1; i <= 10; i++)
cout << i << endl;
I expected the following:
1
2
3
4
5
6
7
8
9
10
11
When it comes to the last iteration i is 10.
Then i++ increments, but returns the old value 10.
So, condition is again true.
Now, i in the body of if is 11.
Apparently, I am wrong.
Does the postfix increment operator function differently within a for
construct?
cout << i << endl;
I expected the following:
1
2
3
4
5
6
7
8
9
10
11
When it comes to the last iteration i is 10.
Then i++ increments, but returns the old value 10.
So, condition is again true.
Now, i in the body of if is 11.
Apparently, I am wrong.
Does the postfix increment operator function differently within a for
construct?