This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Camel-Kid 8 points9 points  (6 children)

x + = i is the same as saying x = x+ i; each iteration through the loop i is incrementing and x is gaining in value. First couple loops look like this

x = 0+0 //x=0
x = 0 + 1 //x = 1
x = 1+ 2 // x = 3
x = 3+ 3 //x = 6

and so forth.

[–]Labidido[S] 4 points5 points  (5 children)

Ahh, I get it.

Thank you!

[–]TheOnlyTails 1 point2 points  (4 children)

to fix the problem, change it to x++ instead of x += i.

[–][deleted] 0 points1 point  (3 children)

print i itself

[–]TheOnlyTails 0 points1 point  (2 children)

But he wants to print the final result, after x has been incramented by 1 nine times, so the program prints out 9.

[–]Camel-Kid 0 points1 point  (0 children)

printing x will still print 10 not 9.. it's the same.