What's wrong with this for loop?
<p>I'm making a dice game for android and i have this loop that fills an array with the numbered rolled at roll "j". It went like this</p>

<pre><code>int[] rolls = new int[6];
    for (int j : rolls) {
        rolls[j] = (int) (Math.random() * 5);
        rolls[j]++;
        Log.i(getClass().getName(), "Rolls[" + j + "] = " + rolls[j]);
    }
</code></pre>

<p>Except the output (in the logfile is this)</p>

<pre><code>Rolls[0] = 4
Rolls[0] = 2
Rolls[0] = 3
Rolls[0] = 6
Rolls[0] = 3
Rolls[0] = 4
</code></pre>

<p>And when i change the code to this</p>

<pre><code>int[] rolls = new int[6];
    for (int j = 0; j &lt; rolls.length ; j++) {
        rolls[j] = (int) (Math.random() * 5);

        rolls[j]++;
        Log.i(getClass().getName(), "Rolls[" + j + "] = " + rolls[j]);
    }
</code></pre>

<p>the output is correct</p>

<pre><code>Rolls[0] = 4
Rolls[1] = 2
Rolls[2] = 3
Rolls[3] = 6
Rolls[4] = 3
Rolls[5] = 4
</code></pre>

<p>I must be doing something stupid somewhere.</p>
