How do you use a Matrix to toggle between multiple fields from multiple blocks? I have 1 Matrix field:
contentBlock

With 2 Block types:
text
photo

With nested fields:
text -> text
photo -> photo

My attempt at using if statements, which didn't work, to toggle between text and photo looks like the following:

{% for block in entry.contentBlock %}
    {% if block.type == 'text' %}
        {{ block.text }}
    {% endif %}
    {% elseif block.type == 'image' %}
        {% set image = block.image.first() %}
            {% if image %}
                &lt;img src="{{ image.getUrl('thumb') }}" alt="{{ image.title }}"&gt;
            {% endif %}
{% endfor %}


Would using {% switch %} be a better method, or was I close to correct using the if statements?
I think getting the hang of this will open up the true posibilities of using Craft Matrix fields.

Thank you for any input on this question.
Using switch is a good way to handle this, but it looks like your conditionals are just a little off:

{% for block in entry.contentBlock %}
    {% if block.type == 'text' %}
        {{ block.text }}
    {% elseif block.type == 'photo' %}
        {% set photo = block.photo.first() %}
        {% if photo %}
            &lt;img src="{{ photo.getUrl('thumb') }}" alt="{{ photo.title }}"&gt;
        {% endif %}
    {% endif %}
{% endfor %}


The same thing with the switch syntax would be:

{% for block in entry.contentBlock %}

    {% switch block.type %}
        {% case "text" %}
            {{ block.text }}
        {% case "photo" %}
            {% set photo = block.photo.first() %}
            {% if photo %}
                &lt;img src="{{ photo.getUrl('thumb') }}" alt="{{ photo.title }}"&gt;
            {% endif %}
    {% endswitch %}

{% endfor %}