[comp.lang.c] Incorrect loop coding?

JJL101@psuvm.psu.edu (J.J. Lehett) (08/22/90)

      Second time trying to solve this particular problem.... the first time
I guess I didn't spell it out properly.

   Anyways.... here's the code.....



int array[20][20], index1, index2;

main()
{
    for (index1 = 0 ; index1 < 10; index1++)
        for (index2 = 0; index2 < 10; index2++)
            array[index1][index2] = index2;
}

   What happens is it increments the inner loop all the way to 10 after 1
iteration.  Yes, I have put more {'s in to make sure the Turbo C compiler
knew that each was nested, but still to no effect, however, when I
removed the index2++ from the for clause and moved it to the end of the
loop statement itself, it worked fine.

   Seems like it is evaluating index2 to 10 for some unknown reason.

   Any help would be greatly appreciated.

    Thanks in advance,

********************************************************************
*       J.J.        *             JJL101@psuvm.bitnet              *
*                   *    Penn State Center for Academic Computing  *
*    John Lehett    *          Computational Mathematics           *
********************************************************************