Rather than using a nested for loop, which tends to confuse, how about using a counter for the size of the rows.