How do I clear deprecation errors for looping through element queries? I am getting this depreciation messages.  


  Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.


In the example below, the depreciation message refers to the 2nd loop for flag in country.  The message appears anytime I have a loop within a loop.     

How do I template this to avoid the deprecation message?

{% set entries = craft.entries.section('posts').all() %}

{% for first in entries[0:1] %}

{% set country = first.countryName %}

{% for flag in country %} 
&lt;span class="flag-icon flag-icon-{{ flag.countryCode }}"&gt;&lt;/span&gt;
{% endfor %}

&lt;span&gt;{{ first.title }}&lt;/span&gt;

 {% endfor %}
What about using the all() function as well? Your field doesn't contain an array, it contains the same type of object like craft.entries provides.

{% for flag in country.all() %}


It doesn't appear because you have a loop in a loop it appears because you treat and object as an array