## looping/array iterator problem

Hi Gang,

I have a function that I have built and its breaking. The function takes 3 parameters: an array, a itemcount, and a table column width number. it builds a table with N td cells, and in each cell there will be 'itemcount' elements from the array.

As it stands the function breaks at a point inside the cell building when it's looping through the array elements. I think the loop may be running off the end of the array and busting and/or never satisfying the exit condition.
It important to note that if I comment out the 'busting line' and uncomment the 'working line' the function works fine. This has something to do with using the array iterator and controlling it properly. Please can someone have a look and point me in the right direction? I have included the whole function at the end.

Best regards,
DE

The isolated snippet is:
Code:

if(i<dataArray.length){
do{
//Here is line below that busts!
/* busting line*/ tableBlock += (dataArray[i].name);
/* working line */

//Im checking to see if I reached the end of the array and bust out if I did, not sure this logic is working properly.
if(i == dataArray.length){
break;
}else{
i++ ;
}
}while( (i % rc)!= 0 )
}//end if

//the whole function:

Code:

function buildMatrixX(dataArray, rc, w){

g = Math.round( dataArray.length / (rc * w) ); //results per row
i = 0; //sentinel
n = 0; //sentinel

tableBlock = "<table>";

do{
tableBlock += "<tr>";

//=========================================================
for(j=0; j < w; j++){

tableBlock += "<td>";

//=========================================================
if( i < dataArray.length ){

do{
//Here is line below that busts!
tableBlock += (dataArray[i].name);
if(i == dataArray.length){
break;
}else{
i++ ;
}

}while( (i % rc)!= 0 )

}//end if

//=========================================================
tableBlock += "</td>";

}//end for
//=========================================================

tableBlock += "</tr>";
n++;

}while( n < g )

tableBlock += "</table>";

return tableBlock;
}