Bootstrap 4 Accordion with Matrix (and SuperTable)
I'd break up the forloops a bit so you're outputting the panel container and the accordion wrapper markup once. Then for each accordion (supertable row) you're outputting that markup as many times as it's needed.

I haven't used Bootstrap JS packages for a long time, so I was a bit thrown by the amount of divs you have. (I use this accordion package for how simple it is. It's an oldie, but a goodie and is still being maintained.)

{# Matrix loop of blocks #}
{% for row in entry.contentBuilder.all() %}

    {% switch block.type.handle %}
    {% case 'accordion' %}

         &lt;div class="container"&gt;
             &lt;div class="row"&gt;
                 &lt;div class="col-md-12"&gt;
                     &lt;div class="accordion" id="accordion"&gt;

                         {# Supertable loop of accordions #}
                         {% for block in row.components.all() %}

                             &lt;div class="card"&gt;
                                 &lt;div class="card-header" id="heading{{ loop.index }}"&gt;
                                     &lt;h5 class="mb-0"&gt;
                                         &lt;button class="btn btn-link" data-toggle="collapse" data-target="#collapse{{ loop.index }}" aria-expanded="true" aria-controls="collapse{{ loop.index }}"&gt;
                                              {{ block.accordionTitle }}
                                          &lt;/button&gt;
                                     &lt;/h5&gt;
                                 &lt;/div&gt;

                                 &lt;div id="collapse{{ loop.index }}" class="collapse {{ loop.first ? 'show' }}" aria-labelledby="heading{{ loop.index }}" data-parent="#accordion"&gt;
                                     &lt;div class="card-body"&gt;
                                         {{ block.accordionCopy }}
                                     &lt;/div&gt;
                                 &lt;/div&gt;
                             &lt;/div&gt;

                        {% endfor %}

                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    {% endswitch %}
{% endfor %}