title: Foreach vs common for loop
body: <p>I just started learning Java and the first thing I came across is the <code>foreach</code> loop, not knowing the way it works the first thing I did was:</p>
  
  <pre><code>int[] array = new int [10];
  for (int i: array){
      i = 1;
  }
  </code></pre>
  
  <p>And obviously failed to assign <code>1</code> to every element of the array. Then I added <code>System.out.print(i);</code> (after <code>i = 1;</code>) to the body of the loop and saw that the output of the screen was <code>1111111111</code> but since doing something with <code>i</code> inside the loop is valid that most likely <code>i</code> is a copy of every element of the array, ain't it? (first questions)</p>
  
  <p>If the above is true doesn't this mean that the <code>foreach</code> loop is much slower then the common for loop since it involves making copies of each element of the array? Or since <code>Java</code> doesn't have pointers and pointer arithmetic, the <code>oprator[]</code> may be designed in some other "badly" fashion that copying every element is actually faster?</p>
  
  <p>And if the above assumptions are true, why one would use an obviously slower <code>foreach</code> loop instead of a common <code>for</code>loop?</p>
  
  <p>In short the questions:</p>
  
  <ul>
  <li><p>Is <code>i</code> the copy of each element of the <code>array</code>? If not what is it
  then?</p></li>
  <li><p>Isn't the <code>foreach</code> loop slower then the common one? If not, how
  "badly" is then <code>operator[]</code> designed?</p></li>
  <li><p>There is nothing more except readability to win in a <code>foreach</code> loop?</p></li>
  </ul>