For loop that can accept array and element query without throwing .all deprecation error I have a component that accepts both hardcoded objects and entry queries. This allows us to have components that can be used independent of the database.

Hardcode include:

{% include '_components/callToAction' with {
    headline: 'Hardcode call to CTA Headline',
    body: 'Hardcode call to CTA',
    items: [
      { name: 'item1'},
      { name: 'item2'} 
    ]
} %}


db include:

{% include '_components/callToAction' with {
    entry: entry.callToAction
} %}


Component:

{% set component = {
  headline: headline ?? entry.headline ?? null,
  body: body ?? entry.body ?? null,
  items: items ?? entry.items ?? null
} %}

&lt;h1&gt;{{ component.headline }}&lt;/h1&gt;
&lt;p&gt;{{ component.body }}&lt;/p&gt;

{% for item in component.items %}
  {{ item.name }}
{% endfor %}


Both those work fine, but with Craft 3 we're getting deprecation errors for not using .all() when it is an element query which is drastically increasing our db queries on the pages that use several of these components.
Instead of trying to loop through an object (your Query) you could just execute it

{% set component = {
    headline: headline ?? entry.headline ?? null,
    body: body ?? entry.body ?? null,
    items: items ?? entry.items.all() ?? null
} %}

&lt;h1&gt;{{ component.headline }}&lt;/h1&gt;
&lt;p&gt;{{ component.body }}&lt;/p&gt;

{% for item in component.items %}
    {{ item.name }}
{% endfor %}


or if that doesn't fit your case, you can do it before

{% set relatedEntry = entry.callToAction.one() %}
{% include '_components/callToAction' with {
    entry: relatedEntry,
    items: relatedEntry.items.all()
} %}


You could as well check if your variable is an object of type EntryQuery

{% if className(entry) == 'craft\elements\db\EntryQuery' %}
    {% set entry = entry.one() %}
{% endif %}


Note: since you had multiple of these deprecated errors I wasn't exactly sure which one you wanted to "solve" and which one is "intended"