0
Output question in for loop i+=2...
Hey again. I know this should be simple but when I run through the loop I end up with a total number of 8 instead of 9. Why? https://code.sololearn.com/cykspkAKhoVl/?ref=app
4 Answers
+ 2
why do you think i stops at 6?
why donât you try printing i in the loop and see whatâs going on
+ 1
Since there is an increment operation on i (i.e, i++) it initially holds 7. And then i+2 is 9
0
But if I do this: for (i = 0; i<=6; i++){
cout << i;
Then it runs until 6, so 0123456... I guess I get confused with the 0, which means the loop runs 7 instead of 6 times, yes? :)
0
Thanks again for your answers!!