Nicole
Nicole

Reputation: 39

Nested forEach loop (JSTL/JSF)

I'm new at this and I'm currently editing a friend's existing code, I just wanted to know if there's a simple way of doing a nested for loop in JSTL/JSF for a Java code similar to this one:

blocks=0;
for(vElement=0; blocks<19; vElement++){
   for(hElement=0; exit<1; hElement++){
      System.out.println(blocks);
      if(blocks!=18){
          blocks++;
      } else{
          exit = 1;
      }
   }
   System.out.println("\n");
}

The output would be something like this:

0   1   2   3   4   5   6
7   8   9   10  11  12  13
14  15  16  17  18

Everything I've seen on here has something to do with a Backing Bean (and I don't really need that for this one). Any suggestions?

Upvotes: 3

Views: 2480

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240900

<c:forEach var="i" begin="0" end="2">
  <c:forEach var="j" begin="0" end="6">
     <c:if test="${(i*7 + j) <=18}">
                       <c:out value="${(i*7 + j)}" />
     </c:if>
  </c:forEach>
  <br />
</c:forEach>

Note: haven't tested

Cloning BalusC's request I have also added new request

Also See

Upvotes: 3

Related Questions