tokhi tokhi - 2 months ago 23
Java Question

for loop to jstl forEach

How to convert below

for
loop to a
jstl
foreach
:

for(int i = 0 ; i<=21; i+=3){
// print foo
}


This is what I have so far:

<c:forEach varStatus="loop" begin="0" end="21">
// display foo
</c:forEach>

Answer

Acoording to jstl you should try:

<c:forEach begin="0" end="21" step="3" varStatus="loop">
    <c:out value="${loop.count}"/>
</c:forEach>
Comments