Grid using Arrays and While Loop?
              in 
             Programming Questions 
              •  
              2 years ago    
            
 
           
             I'm trying to create a square grid of circle objects using a while loop, but i keep ending up with 'i' getting too large or the last column not getting filled in.  I want my grid to appear typewriter style, going across each column before going down a row, which is why I'm not just using 2 nested for loops.  Here's the loop i'm using to initialize the objects, any ideas what's wrong with this code?
            
             
            
            
             
              
             
              
           
 
            
           
              int i = 0;
             
             
              int j = 0;
             
             
              while (i < cols){
             
             
                  if (i == cols-1 && j< rows-1){
             
             
                    j++;
             
             
                    i=0;
             
             
                }
             
             
                 grid[j][i] = new Circle(i*20,j*20,20,20,i*10,i*20,i*20);
             
             
                 i++;
             
             
              }
             
             
              
              1  
            
 
            