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

25th Jun 2020, 9:38 AM
The_Fox
The_Fox - avatar
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
25th Jun 2020, 10:38 AM
Bobby Fischer
Bobby Fischer - avatar
+ 1
Since there is an increment operation on i (i.e, i++) it initially holds 7. And then i+2 is 9
25th Jun 2020, 9:50 AM
123
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? :)
25th Jun 2020, 11:01 AM
The_Fox
The_Fox - avatar
0
Thanks again for your answers!!
25th Jun 2020, 11:01 AM
The_Fox
The_Fox - avatar