PDA

View Full Version : For Loop in C



brown
10-14-2009, 05:03 PM
Hi I'm learning C++ now and have problem with for loop.
Code:

int i = 0;

for(int j = i,i=10; j < 5; ++j ) {
cout << i , "\t" , j, "\n";
}



The program prints 1010101010. I'm using g++ compiler. Can anyone please explain what's happening ???
Regards

alfiealvins
11-26-2010, 06:58 PM
Output must be defined below.
10 0
9 1
8 2
7 3
6 4
5 5
6 4
7 3
8 2
9 1
10 0