I'm going to assume your array is 10x10, in which case you need to set genX to 0 when genX equals 9 - the last column in the array.
However, I don't suggest looping through arrays like this - it's simply messy and convoluted. Standard procedure when looping through a 2D array is to use a nested For loop to go through the rows and columns. Example:
<img src="http://i.imgur.com/RjwJcnZ.png" border="0" />
Note that the bounds on For loops are inclusive, so each of these loops will go from 0 to 9 including 0 and 9.