title: Playframework: Looping over a list
body: <p>I have a list that I'm passing back to the view. </p>
  
  <pre><code>public static Result index() {
  
          List&lt;String&gt; list = new ArrayList&lt;String&gt;();
          list.add("idea 1");
          list.add("idea 2");
          list.add("idea 3");
          list.add("idea 4");
          list.add("idea 5");
          list.add("idea 6");
          list.add("idea 7");
  
          return ok(index.render(list));
  }
  </code></pre>
  
  <p>I'd like to iterate over it 3 at a time so that it's displayed like so:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;idea 1&lt;/li&gt;
      &lt;li&gt;idea 2&lt;/li&gt;
      &lt;li&gt;idea 3&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul&gt;
      &lt;li&gt;idea 4&lt;/li&gt;
      &lt;li&gt;idea 5&lt;/li&gt;
      &lt;li&gt;idea 6&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul&gt;
      &lt;li&gt;idea 7&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I'm unable to figure out how to do this using the for loop.</p>
  
  <p>I have the Java code for this, just unable to translate this to the Play framework template code:</p>
  
  <pre><code>        int size = list.size();
          int loopSize = (int) Math.ceil(size / 3.0);
          int counter = 0;
  
          for(int j = 0 ; j &lt; loopSize; j++) {
  
              System.out.println("---------------------");            
  
              for (int i = 0; i &lt; 3; i++) {
                  if(counter &lt; size) {
                      System.out.println(list.get(counter));
                      counter++;
                  } else {
                      break;
                  }
              }
  
              System.out.println("---------------------");
          }
  </code></pre>