Need help transforming echo to return for use with shortcode

There’s two ways to do it.

First, you could put any HTML into a string, and concatenate it with ., and .= to add a string to an existing value. This way you can build up a large string and return it at the end:

function torque_hello_world_shortcode() {
    $html="";

    if ( function_exists( 'get_coauthors' ) ) {
        $coauthors = get_coauthors();

        foreach ( $coauthors as $coauthor ) {
            $html .= '<div><span class="authorboxsinglename">' . $coauthor->display_name . '<span></div>';
            $html .= '<div><span class="authorboxsinglebio">' . $coauthor->description . '</span></div>';0
        }
    }

    return $html;
}

(You don’t need to have opening PHP tags on every line.)

Or, you could use ‘output buffering’ to capture all the output, and then return it at the end. This is more useful when dealing with large amounts of HTML. To start capturing use ob_start() and to get the captured output use ob_get_clean():

function torque_hello_world_shortcode() {
    ob_start();

    if ( function_exists( 'get_coauthors' ) ) {
        $coauthors = get_coauthors();

        foreach ( $coauthors as $coauthor ) {
            ?>

            <div><span class="authorboxsinglename"> <?php echo $coauthor->display_name; ?> <span></div>
            <div><span class="authorboxsinglebio"> <?php echo $coauthor->description; ?> </span></div>

            <?php
        }
    }

    return ob_get_clean();
}