It is better to do that with CSS and not with markup or server side scripting. Let me give you an example:
.grid:nth-child(5n+5), .grid.fifth-child { clear: both; }
It's not supported in every browser so you can use jQuery to fix that:
$('.grid:nth-child(5n+5)').addClass('fifth-child');