Hii ,
Data reader reads table rows into the 2d array. The array fills with the last row of the table. How many loops are there?. Why :?:

``````Input Table :
-----------------------
id red green blue
1101 12 11 13
1102 12 12 14
1103 13 14 13
------------------------``````
``````while (reader->Read()) // READS 12 ITEMS (Above)
{
for(int i=1; i<4; i++) // (loops 3*4 times)
{
}

}``````

You have 4 rows shown, so it (the Read()) will loop 4 times.
The inner loop loops 3 times from 1-to-3
4 on the outside, 3 on the inside. 12 loops.
I was thinking 16 earlier, then realized you start that inner loop at …

## All 3 Replies

You have 4 rows shown, so it (the Read()) will loop 4 times.
The inner loop loops 3 times from 1-to-3
4 on the outside, 3 on the inside. 12 loops.
I was thinking 16 earlier, then realized you start that inner loop at 1 instead of 0.

Now, for that data, you only need the reader to loop because you are specifically putting the data into each "column" of the array.

The "row" of the array is then the only thing that is changing (to keep all of the data).

/*remove the inner loop*/
The only thing that you would keep from that inner loop is the variable i as a counter to tell the 2d array which "row" is used to store the data.