It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

modulus and/or iterator busting

modulus and/or iterator busting

Postby deepsnow on Tue Jul 29, 2008 4:15 pm

Hi Gang,
First time at these forums, so 'Greetings!"

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.
Thanks in advance for any help you can offer.

Best regards,
DE

The isolated snippet is:
Code: Select all
               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: Select all
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;
}
deepsnow
 
Posts: 0
Joined: Tue Jul 29, 2008 3:56 pm

Postby rangana on Tue Jul 29, 2008 11:29 pm

Could you show us the markup involved. We'll try to reproduce the problem at our end.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 4 guests