As Milo noted, the final result might look something like the following
if ($wp_query->have_posts()) {
while ($wp_query->have_posts()) {
$wp_query->the_post();
$post_title = get_the_title();
# On the first pass, write the start of your single container
if ( 0 == $wp_query->current_post ) {
echo '<div class="container">';
}
echo <<<HTML
<div class="different-post-style">
{$the_title}
</div>
HTML;
# On the 3rd pass, close your single container
if ( 2 == $wp_query->current_post ) {
echo "\r\n</div>";
}
}
# Close the div if there were 2 or fewer posts
if ( $wp_query->current_post < 2 ) {
echo "\r\n</div>";
}
}
Modified as per Milo’s comment. I hadn’t thought of that.