Home page loop once, other pages loop through all I only want one block on the home page, other pages can loop through all of them. Is there a more efficient way to write this?

{% if craft.request.getSegment(1) is empty %}
        {% for block in memberships.memberships.limit(1) %}
        &lt;a href="{{ block.urlLocation }}" class="center" target="_blank"&gt;
            {% for asset in block.logo %}
                &lt;img src="{{ asset.url('memberships')}}" alt="{{ asset.title }}" /&gt;
            {% endfor %}
        &lt;/a&gt;
        {% endfor %}
    {% else %}
        {% for block in memberships.memberships %}
        &lt;a href="{{ block.urlLocation }}" class="center" target="_blank"&gt;
            {% for asset in block.logo %}
                &lt;img src="{{ asset.url('memberships')}}" alt="{{ asset.title }}" /&gt;
            {% endfor %}
        &lt;/a&gt;
        {% endfor %}
    {% endif %}
You could do it this way:

{% set blockLimit = entry.section.isHomepage() ? 1 : null %}

{% for block in memberships.memberships.limit(blockLimit) %}
  &lt;a href="{{ block.urlLocation }}" class="center" target="_blank"&gt;
    {% for asset in block.logo %}
      &lt;img src="{{ asset.url('memberships')}}" alt="{{ asset.title }}" /&gt;
    {% endfor %}
  &lt;/a&gt;
{% endfor %}


entry.section returns the SectionModel for the entry, and isHomepage() tells you whether that section is the homepage. Then you set your limit accordingly.