How to separate post titles with a comma in the loop?

Instead of outputting everything immediately, save it to a variable so you can conditionally add a comma (and presumably a space) between items:

<?php
// The Loop
if ( $query->have_posts() ) {
    // Save the number of posts found
    global $wp_query;
    $total_posts = $wp_query->post_count;
    // Set a counter variable
    $i=0;
    while ( $query->have_posts() ) {
        $query->the_post();
        // Save the title to a variable instead of outputting
        $output .= get_the_title();
        // Increment the counter each time
        $i++;
    }
    // Outside the loop, since you only want 1 comma each time
    if($i != $total_posts) {
        // Add a comma and a space
        $output .= ', ';
    }
    // Last but not least, display the output
    echo $output;
}
?>