reusing code in function and running it with loop

You would need to set up the function like this in your functions.php

function my_function(){
   //your function in here
   include(TEMPLATEPATH . '[variable][1].php');
}

And then in your loop you would call it like so:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 4,
);

$featured_query = new WP_Query($args);

if ($featured_query->have_posts()) {
    while ($featured_query->have_posts()) {
        $featured_query->the_post();

        ?>
        <ul>
        <li><?php my_function(); ?></li>
        <li><?php the_title(); ?></li>
        <li><a href="https://wordpress.stackexchange.com/questions/131928/<?php echo get_permalink(); ?>"><?php echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail'); ?></a></li>
        </ul>

        <?php

    }
    wp_resetpostdata();
}