Site icon Hip-Hop Website Design and Development

Easy methods to declare a variable in a loop and make it obtainable within the template file

I used to be confronted with a minor situation however cannot resolve it myself. I would like so as to add the worth on the variable in any case loop iterations. And nothing drawback, however I would like to make use of this variable within the different file. for instance:

whereas( have_posts() ) {
        the_post();
        $x = '';
        $x++;
        get_template_part( 'content material', 'proper' );
    }

Now I have to get the $x worth with iteration in content-right.php I attempt to declare a variable into this file however on this case no iteration. Is there any option to resolve this?