title: Rotate Squared Matrix java solution: Why it works?
body: <p>I want to solve the following problem: You are given an n x n 2D matrix representing an image.
  Rotate the image by 90 degrees (clockwise) in-place. I found one very nice solution here: <a href="http://n00tc0d3r.blogspot.de/2013/05/rotate-image.html" rel="nofollow">http://n00tc0d3r.blogspot.de/2013/05/rotate-image.html</a> Namely,</p>
  
  <pre><code>     public void rotate(int[][] matrix) {  
     for (int level = 0, len = matrix.length; level &lt; len; ++level, --len) {  
       int end = len - 1;  
       for (int pos = level; pos &lt; end; ++pos) {  
         int tail = matrix.length - pos - 1;  
  
         int tmp = matrix[level][pos];  
         // left -&gt; top  
         matrix[level][pos] = matrix[tail][level];  
         // bottom -&gt; left  
         matrix[tail][level] = matrix[end][tail];  
         // right -&gt; bottom  
         matrix[end][tail] = matrix[pos][end];  
         // top -&gt; right  
         matrix[pos][end] = tmp;  
       }  
     }  
   }  
  </code></pre>
  
  <p>I see that it works, and I understand the idea, but my question is why we use <code>++level</code> instead of <code>level++</code> and why we use <code>--len</code> instead of <code>len--</code>. I tried both was and it worked fine for me. However for such problems (non trivial matrix traversal) people always use <code>++level</code> instead of <code>level++</code>. Again my question is <strong>why</strong>?</p>