I came across some velocity variables (1.6.4) that could help you save a couple lines of code.
$velocityCount: Current index of the foreach loop (starts at 1)
$velocityHasNext: Checks if there is another item in the loop
-Freemarker version
(Source: velocity.apache.org)