How I can repeat 2 HTML templates in a WordPress Query?

I know that you are ESL but I think we will need a few more details. You need to better comment your code, it is very confusing.

I will take a guess though.

Have a look a the Modulo % operator.

# Helper to simulate the while, replace this with `$wp_query->get_posts()` or similar
$posts = function() {
    static $posts = 20;
    $posts--;
    return $posts < 0 ?: $posts;
};
$counter = 0;
echo "Looping Posts".PHP_EOL;
while( $posts() ) {
  $counter++;
  echo "Post: {$counter}".PHP_EOL;
  if( $counter % 4 == 1 ) {
    /* template A? */
    echo ' (A)~~> Posts: 1, 5, 9, 13, 17, etc…'.PHP_EOL;

  } elseif( $counter % 4 == 2 ) {
    /* template B? */
    echo ' (B)~~> Posts: 2, 6, 10, 14, 18, etc…'.PHP_EOL;

  } elseif( $counter % 4 == 3 ) {
    /* template C? */
    echo ' (C)~~> Posts: 3, 7, 11, 15, 19, etc…'.PHP_EOL;

  } elseif( $counter % 4 == 0 ) {
    /* template D? */
    echo ' (D)~~> Posts: 4, 8, 12, 16, 20, etc…'.PHP_EOL;
  }
}

Example here on 3v4l.org, that you can try interactively.

Output:

Looping Posts
Post: 1
 (A)~~> Posts: 1, 5, 9, 13, 17, etc…
Post: 2
 (B)~~> Posts: 2, 6, 10, 14, 18, etc…
Post: 3
 (C)~~> Posts: 3, 7, 11, 15, 19, etc…
Post: 4
 (D)~~> Posts: 4, 8, 12, 16, 20, etc…
Post: 5
 (A)~~> Posts: 1,