Wrap every month posts in div

$last_month = null;

while ( $the_query->have_posts() ) :
    $the_query->the_post();
    $the_month = get_the_time( 'Ym' ); // e.g. 201611

    if ( $last_month !== $the_month ) {
        if ( $last_month !== null ) {
            // Close previously opened <div class="row" />
            echo '</div>';
        }

        echo '<div class="row">';
    }

    $last_month = $the_month;

    ?>

    <div class="col-3">
        <?php the_title(); ?>
    </div>

    <?php

    if ( $the_query->current_post + 1 === $the_query->post_count ) {
        // Last item, always close the div
        echo '</div>';
    }

endwhile;

tech