c++ - Why for(int i=0; i<10; ++i) and for(int i=0; i<10; i++) return the same? -


why

for(int i=0; i<10; i++)     std::cout << << std::endl; 

and

for(int i=0; i<10; ++i)     std::cout << << std::endl; 

return same:

0 1 2 3 4 5 6 7 8 9 

i expecting pre-increment return:

1 2 3 4 5 6 7 8 9 10 

since increments self before return, right?

a for loop like

for(int i=0; i<10; i++)     std::cout << << std::endl; 

is same following:

{     int = 0;  // loop initializer     while (i < 10)  // loop condition (and actual loop)     {         std::cout << << std::endl;  // loop body         i++;  // loop post-expression     } } 

now changing loop "post-expression" i++ ++i not make difference, since result thrown away, , it's performed @ end of loop.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -