title: Reversing a nested loop
body: <p>I am trying to reverse this code so that I can print a diamond shape with a border around it. What is the best way to begin reversing a nested loop/series of loops? I tried tinkering around with the code but everything comes out jumbled and out of order. Any advice?</p>
  
  <p>Also, is there a way to make an even number of .'s on each side of the stars at the top? The only way I have been able to make it work prints an even amount on each side by one...</p>
  
  <p>Here is what should be printed to the console: <a href="http://i.imgur.com/h55r2.jpg" rel="nofollow">http://i.imgur.com/h55r2.jpg</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class SixTester {
  
      public static void main(String[] args)
      {
              int i,j,k;
              int numOfRows = 8;  // Made this a variable, so that the program can make any size diamond (try playing around with different values eg. 2 or 16)
  
              // Step 1. The first Dash
              for(i=0;i&lt;numOfRows*2 +2;i++)
                      System.out.print(" "); // Number of spaces is double the number of rows in your 'Half Pyramid'
              System.out.println("-");
  
              // Step 2. The First half diamond
              for (j=0; j&lt;numOfRows ; j++ )
              {
                      for(k=numOfRows*2; k&gt;1+j*2; k--)
                              System.out.print(" ");
  
                      System.out.print("_/");
                      for (i=0; i&lt; 2+j*4; i++)
                      {
                              // Prepare the Star rectangle, Note that it starts half the way (rows/2)
                              if(j &gt;= numOfRows/2 &amp;&amp; (i&gt;j*2- numOfRows/2 &amp;&amp; i&lt;j*2+ numOfRows/2)) {
                                      System.out.print("*");                                 
                              }
                              else
                                      System.out.print(".");
                      }
                      System.out.println("\\_");
              }
              // Next Step  - Make the bottom pyramid...but how to reverse?
      }
  }
  </code></pre>