# For loop execution time

**URL:** <https://community.thunkable.com/t/for-loop-execution-time/2619990>\
**Category:** Questions about Thunkable X\
**Tags:** for-each\
**Created:** [September 29, 2023, 12:07pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990 "2023-09-29T12:07:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [September 29, 2023, 12:07pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/1 "2023-09-29T12:07:59Z")

</div>

I have a 1000 row google sheet as Datasource.  
In a for loop I’m populating a list performing a test for every element of the list  
But it takes a very long time to execute the for loop.  
Is it a web preview problem or a for loop problem?  
In this example I only increment a counter at every for loop iteration.  
It takes almost 10 seconds to scan the 1000 elements list (and it shows only the final 1000 value instead of an incrementing value, but i suppose this can be a problem with screen updating in the web preview)  
Don’t care about “linee” app variable, that should be the final list but in this example I’m not using it having noted the slowness of the procedure.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/6/16a25864d09a423f1eb2af8b9980b3fb8ef14276.png)

Thank you!

---

<div class="post-metadata">

**Author:** ![vishruth-ram](https://avatars.discourse-cdn.com/v4/letter/v/82dd89/32.png) [@vishruth-ram](https://community.thunkable.com/u/vishruth-ram)\
**Post date:** [September 29, 2023, 12:21pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/2 "2023-09-29T12:21:12Z")

</div>

what is the default value of app variable contatore

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [September 29, 2023, 12:34pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/3 "2023-09-29T12:34:21Z")

</div>

The default value is 0

---

<div class="post-metadata">

**Author:** ![vishruth-ram](https://avatars.discourse-cdn.com/v4/letter/v/82dd89/32.png) [@vishruth-ram](https://community.thunkable.com/u/vishruth-ram)\
**Post date:** [September 29, 2023, 12:35pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/4 "2023-09-29T12:35:45Z")

</div>

If only you put the default value to 0 and set the code to increment to the length of the list then you will get 1000 only

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [September 29, 2023, 12:51pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/6 "2023-09-29T12:51:41Z")

</div>

What?  
As you can see, I’m incrementing CONTATORE every iteration. So I get the incrementing value at every iteration (and it is so if I insert a delay), no problem about that, that is not my problem.  
The problem is that it takes 10 seconds to reach the value 1000.

---

<div class="post-metadata">

**Author:** ![tthompson41231](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tthompson41231/32/161401_2.png) [@tthompson41231](https://community.thunkable.com/u/tthompson41231)\
**Post date:** [September 29, 2023, 2:03pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/7 "2023-09-29T14:03:47Z")

</div>

Try setting the list of values from your spreadsheet to an app variable then iterate that variable.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [September 29, 2023, 2:42pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/8 "2023-09-29T14:42:57Z")

</div>

> [@tthompson41231](#):
>
> om your spreadsheet to an app var

It seems to work this way.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/e/9eef0150a70ccf23ffab46242ab6eda2ea10e87f.png)

Now the question is, WHY? I expect the for loop to call the list of values only the first time it execute…

---

<div class="post-metadata">

**Author:** ![tthompson41231](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tthompson41231/32/161401_2.png) [@tthompson41231](https://community.thunkable.com/u/tthompson41231)\
**Post date:** [September 29, 2023, 2:52pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/9 "2023-09-29T14:52:25Z")

</div>

App variables are significantly faster. I often convert stored variables to app variables as well.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [December 28, 2023, 2:53pm UTC](https://community.thunkable.com/t/for-loop-execution-time/2619990/10 "2023-12-28T14:53:09Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
