Conditional variables within a certain matrix block type
Why don't you do something like this? You can use switch and case to change the output of each part of the matrix (we call them blocks).

This is part of a snippet to output a documentation matrix that contains code, titles, content etc.

{% for block in entry.documentation %}
    {% switch block.type %}

         {% case 'subsectionTitle' %}
            &lt;h2 id="{{ anchor }}"&gt;{{ block.subsectionTitle }} &lt;a href="#{{ anchor }}" class="pound"&gt;#&lt;/a&gt;&lt;/h2&gt;

        {% case 'description' %}
             &lt;div class="docs-description"&gt;{{ block.description }}&lt;/div&gt;

    {% endswitch %}
{% endfor %}