Archieve page, Advertisement Every 3 Posts

$i = 0;
while (have_posts())
{
    $i++;
    the_post();

    // Output the post
    the_title();
    the_content();

    // Output an ad after each third post
    if ($i % 3 === 0)
    {
        echo 'ad';
    }
}

The % is called the modulus operator.