How can I create a loop to cycle thru each category and the the entries within each category? So, I have a loop that populates all the entries related to a given category. See below.  I have multiple categories.  Right now, I use the same code for each category -  swapping only the name of the category out (e.g, category1, category2 ...).  How can I build a loop that avoids this?

My current template is as follows. I did not include the repetition for each category.   

    &lt;div class="margin-2"&gt;&lt;/div&gt;
        {% set category = craft.entries.seciont('posts') %}


        &lt;h6&gt;Aircraft&lt;/h6&gt;
        &lt;div class="sep red margin-1"&gt;&lt;/div&gt;
        &lt;div class="owl-carousel owl-thumbs"&gt;
            {% for entry in category.relatedTo(craft.categories.slug('category1')) %}
            &lt;div class="thumb dark-overlay"&gt;
                &lt;div class="photo"&gt;
                    &lt;a href="{{entry.url}}"&gt;
                        &lt;img src="{{ entry.postImage.first().getURL('thumbImage')}}" alt="" width="235" height="235"&gt;
                        &lt;span class="info"&gt;&lt;span class="big-excerpt"&gt; {{ entry.title }} k&lt;/span&gt;&lt;/span&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            {% endfor %}
First you loop through the categories then use the category to loop through all the entries related to that category.

{% for category in craft.categories.group('categoryGroup') %}
  {% for post in craft.entries.section('posts').relatedTo(category) %}
    {# your markup #}
  {% endfor %}
{% endfor %}