I am trying to get this to display the 3 columns with div classes of "product first" "product " and "product last" but am missing something and it's only showing "product first" and "product " - no last.

Code:
<%
  if iFirst = 0 then
%>
		<li class="product first">
		</li>
<%
  iFirst = 1
  iCount = iCount + 1
  end if   

  if pgroupIDmain <> pgroupID then  			
  if iCount = 1 then 
  %>
  <%
  end if
  %>
		<li class="product ">
		</li>
<%
  if iCount = 3 then
%>	
		<li class="product last">
		</li>
<%
  iCount = 1
  else
  iCount = iCount + 1
  end if 

  pgroupIDmain = pgroupID 
  end if

  rsTemp1.moveNext
  loop

  if iCount > 1 and iCount < 3 then 
  do while iCount > 1 and iCount < 3 
  iCount = iCount + 1 
%>  
<%
  loop
%>

<%
  end if
  end if
%>