title: How do I convert this for loop into a while loop?
body: <p>I am creating an array program. I am practicing how to convert <code>for</code> loops to <code>while</code> loops, but I cannot grasp the concept. </p>
  
  <p>If I have the <code>for</code> loop: </p>
  
  <pre><code>int [] list = new int [5];
  
  for (int i = 0; i &lt; 5; i++) {
      list [i] = i + 2;
  }
  </code></pre>
  
  <p>How would I make it a <code>while</code> loop?</p>
  
  <p>Here's my attempt</p>
  
  <pre><code>int [] list = new int [5];
  int i = 0;
  
  while (i&lt;5) {
      list [i] = i + 2;
      i++;
  }
  System.out.print(list[i] + " ");
  </code></pre>
  
  <p>This is what I think should be done, but it comes up as an error in my computer.</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at Arrays2.main(Arrays2.java:21)</p>
  </blockquote>
  
  <p>This is line 21</p>
  
  <pre><code>System.out.print(list[i] + " ");
  </code></pre>