Is if statement necessary for empty array situation?

If I don’t include

{% if my_array %}

And have a code such as this:

{% for var in my_array %}
do this heavy task
{% endfor %}

does it skip the “heavy task” if my_array is empty or is it better to include the if statement (performance wise)?
Thank you.

Hi @Ardi94

Aibek is here from Speedimize.io

You can do without checking. This will not affect the performance in any way and the code will be shorter and more concise.

We recommend using it in this form:

{% for var in my_array %}
  if array is not empty do this heavy task
{% else %}
  array is empty
{% endfor %}

If the array is empty, else will be triggered.

Hope that helps you.