Alternate (kinda) color rows

Alternate (kinda) color rows

I would like colored rows that alternate, the code for that i know is simple, but my problem is that i don't want rows to alternate everytime. In other words sometimes i may have 3 consecutive rows with one color and then 2 rows with another color. I don't know exactly after how many rows the color will alternate as that is based on some logic. So i can't use:

$("tr:even").css("background-color", "#F4F4F8");
$("tr:odd").css("background-color", "#EFF1F1");


My code is something like:

<table>
<c:forEach ...some logic...>
<tr>....</tr>
</c:forEach>
</table>

unfortunately putting a div in between <table> and <tr> is not allowed, that would have solved it. So currently i got this to worked using scriplets which i wanted to avoid!

<%if (..some logic..) {%>
<tr class="stripedWhite">

<%} else {%>
<tr class="stripedBlack">
<%}%>

and then i use jquery

$(document).ready(function()
{
//for p.striped
$('.stripedWhite').css('background-color', '#F4F4F8');
$('.stripedBlack').css('background-color', '#DFF1F1');

});


But is there an efficient way to do this without using scriplets?

Thanks!