title: Convert this for loop into a while loop?
body: <p>Trying to convert this code for a for loop into a while loop:</p>
  
  <pre><code>int endData = myScanner.nextInt();   
  int row     =   0;
  int cell    =   0;
  int rowcell =   0;
  
  
      System.out.println("FOR LOOP: ");
      for (row = 1; row &lt;= endData; row++) {
  
          if (row%2 == 0) {
              for (cell = 0; cell &lt; row; cell++) {
                  for (rowcell = 0; rowcell &lt;= cell; rowcell++) {
                      System.out.print(row);
                  }
                      System.out.println("");
              }
  
          }
  
           else {
  
              for (cell = row; cell &gt; 0; cell--) {
                  for (rowcell = cell; rowcell &gt; 0; rowcell--) {
                      System.out.print(row);  
                  }
                      System.out.println("");
              }
  
          }
  
      }
  </code></pre>
  
  <p>So far I have tried this code but it came out completely wrong:  </p>
  
  <pre><code>    row2 = 1;
  
      while (row2 &lt;= endData){
  
          if(row2%2 == 0){
              cell2=0;
              rowcell2 = 0;
              while(cell2&lt;row2){
                  cell2++;
                  while(rowcell2 &lt;= cell2){
                      rowcell2++;
                      System.out.print(row2);
                  } System.out.println("");
          }
  
      }else {
          cell2=row2;
          rowcell2 = cell2;
          while(cell2 &gt;0){
              cell2--;
          }while (rowcell2&gt;0){
              rowcell2--;
              System.out.print(row2);
          }System.out.println("");
      } row2++;
      }
  </code></pre>
  
  <p>For example, when the user inputs a value of 3, the for loop returns the correct answer:<br>
  1<br>
  2<br>
  22<br>
  333<br>
  33<br>
  3  </p>
  
  <p>But the while loop outputs:<br>
  1<br>
  22<br>
  2<br>
  333  </p>
  
  <p>Any ideas as how to go about fixing this while loop?</p>