How to output a placeholder image if an Assets field is empty
Thanks to Brad for the answer, and the solution was to use {% if entry.mainImage|length %} instead of {% if entry.mainImage %} for the conditional. So my working code looked like this:

{% if entry.mainImage|length %}
  {% for asset in entry.mainImage %}
    &lt;img src="{{ asset.url }}" alt="{{ asset.title }}" /&gt;
  {% endfor %}
{% else %}
  &lt;img src="http://placehold.it/130x130/f5f5f5/ccc.png" height="130" width="130" alt="{{ entry.title }}" /&gt;
{% endif %}