I know it’s a little late but I thought this might help if someone else has this problem in the future…
I could not find a native function to check to see if we were in the last post of the loop. My way around this was to set a constant equal to the amount of posts to display on a page (you set this value in the settings) and keep track of how many posts we have displayed. When we are in the last one, you do whatever special stuff you wanted to do. I also could not find a way an easy way to get this so I can to use a “magic number.”
In my case, I wanted to display an <hr /> after each post, but not after the last post (it looked stupid with my template).
<?php
$postCount = 0;
define(POSTS_PER_PAGE,3); //this example assumes i display 3 posts on the main page
while (have_posts()):
the_post();
if (++$postCount !== POSTS_PER_PAGE):
// we're not at the last post, display it regularly
else:
// here is the last post, print it out with your special formatting
endif;
endwhile;
?>