function xxx_function(){

	$rows = 1;
	$cols = 4; ?>

	<div class="xxx-row"> <?php

	if ( $query->have_posts() ){
		while ( $query->have_posts() ){ $query->the_post(); ?>

			<div class="xxx-col"> <?php

			// Do shit here.

			if($rows % $cols == 0){ ?> 
				</div> <div class="xxx-row"> <?php 
			}

			$rows++;
		} ?>
		
		</div> <?php
		$rows = 1;
	}
}