title: Creating a temporary variable in a for loop
body: <p>I had a for loop designed to add 6 values to an arraylist.</p>
  
  <pre><code>ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
  for (int i = list.size(); i &lt; list.size() + 6; i++){
      list.add(2 * i);
  }
  </code></pre>
  
  <p>Now this produces an infinite loop. My question is whether or not I could declare a variable that persists throughout the whole <code>for</code> loop, that isn't <code>i</code> or would I have to declare it before the loop? If I can embed it in the <code>for</code> loop, where would I put it?</p>