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
Post a Comment