Looping through a 2D array (diagonal)?
<p>I have a 6x6 array and want to get always the four next values.
As an example:</p>

<pre><code>0-----
-1----
--2---
---3--
----4-
</code></pre>

<p>So I want to get the sum of (0+1+2+3) and the sum of (1+2+3+4) and this for all diagonals.</p>

<p>I tried something, but unfortunately I only get the first diagonal (from the top left corner, downstairs):</p>

<pre><code>for (int i = 0; i &lt; 3; i++) {
            for (int j = 4; j &gt;= 0; j--) {
                    dosomething..(array[j][i]);
                    dosomething..(array[i + 1][j + 1]);
                    dosomething..(array[i + 2][j + 2]);
                    dosomething..(array[i + 3][j + 3]);
            }
        }
</code></pre>

<p>Also I need to get the next four values for all diagonals, which goes from the buttom upstaris too and I have no clue how to make it..</p>

<p>Edit: here is another example:</p>

<pre><code>A B C D E F
G H I J K L
M N O P Q R
S T U V W X
Y Z 1 2 3 4
6 7 8 9 10 11
</code></pre>

<p>What I want now is the following:</p>

<p>I want to get:</p>

<p>(A, H, O, V)</p>

<p>(H, O, V, 3)</p>

<p>(O, V, 3, 11)</p>

<p>(C, J, Q, X)</p>

<p>(B, I, P, W)</p>

<p>(I, P, W, 4)</p>

<p>and the same thing for all diagonals which go from the buttom upstairs.</p>