# \[SOLVED\] Problem with length of list block

**URL:** https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419
**Category:** Questions about Thunkable X
**Tags:** solved
**Created:** [June 15, 2021, 1:47pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419 "2021-06-15T13:47:22Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![sai1910](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sai1910](https://community.thunkable.com/u/sai1910)
#### Post date: [June 15, 2021, 1:47pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/1 "2021-06-15T13:47:22Z")

</div>

Hello,

I have a `for loop`, inside of which I have a long `if` statement. Within that if statement, I have this block:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/5/459a9092df4ef56a7abb4e920817d120206b30e6.png)

Right after that if statement (but still within the for loop) I am showing the `length` of the same list (IDsAlreadyDisplayed) in an Alert. However, it is giving the result as 0, even though the list has 3 items at the same time (I checked this using a ListView)

If I move the Alert.show block to right under the `insert in list` block, It works perfectly.

Why are the blocks not going in the correct order for the `for loop`?

Full screenshot: (I have collapsed the `if` statement as nothing is of relevance, except the above mentioned insert in list block)

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/b/5b0da5bfb08c8aed1d66ba7287b176a2d5c21b1c.png)

Output of Alert (tested on web version):

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/8/08bb772db1833b70c0aaa0f4a86ebf93f3fd87b4.png)

Proof that the list has more than 1 item:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/1/7128fdf5fbd565bfb793a81a570a789e328b93af.png) (this is a ListView)

Thanks.

---

<div class="post-metadata">

### Author: ![sketch](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sketch/32/109058_2.png) [@sketch](https://community.thunkable.com/u/sketch)
#### Post date: [June 15, 2021, 2:12pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/2 "2021-06-15T14:12:46Z")

</div>

Is the IDsAlreadyDisplayed.  
Initialized with a create list block?

---

<div class="post-metadata">

### Author: ![sai1910](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sai1910](https://community.thunkable.com/u/sai1910)
#### Post date: [June 15, 2021, 2:52pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/3 "2021-06-15T14:52:10Z")

</div>

Yes, I initialized it with an ` empty list` block.

---

<div class="post-metadata">

### Author: ![sketch](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sketch/32/109058_2.png) [@sketch](https://community.thunkable.com/u/sketch)
#### Post date: [June 15, 2021, 2:58pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/4 "2021-06-15T14:58:26Z")

</div>

May we see some more screenshots or a link then?

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [June 15, 2021, 3:00pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/5 "2021-06-15T15:00:37Z")

</div>

You need to show the full statement. You assumed there is no issues with the part you collapsed which means you want us to fucus on what you are focusing on and therefore no one will get a result.

Allow others to see and evaluate the situation you are facing instead of steering them on a specific part that you decided upon.

Meanwhile, insert a `wait` block before the `notifier1 message` and if this does not work then move the `wait` block after the `notifier1 message`

---

<div class="post-metadata">

### Author: ![sai1910](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sai1910](https://community.thunkable.com/u/sai1910)
#### Post date: [June 15, 2021, 3:19pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/6 "2021-06-15T15:19:15Z")

</div>

> [@muneer](#):
>
> full statement

Here:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/d/8d20b7e353068c2b1f9bef50fc97484fba3a5c18.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/3/b3104d68dc144dc2af3137fd11d1ff7010bf726a.png)

> [@muneer](#):
>
> insert a `wait` block before the `notifier1`

Ok, will try

---

<div class="post-metadata">

### Author: ![sai1910](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sai1910](https://community.thunkable.com/u/sai1910)
#### Post date: [June 15, 2021, 3:25pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/8 "2021-06-15T15:25:25Z")

</div>

There’s the insert at last block

---

<div class="post-metadata">

### Author: ![sketch](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sketch/32/109058_2.png) [@sketch](https://community.thunkable.com/u/sketch)
#### Post date: [June 15, 2021, 3:26pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/9 "2021-06-15T15:26:00Z")

</div>

yeah i already saw it

---

<div class="post-metadata">

### Author: ![sai1910](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sai1910](https://community.thunkable.com/u/sai1910)
#### Post date: [June 15, 2021, 3:48pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/10 "2021-06-15T15:48:22Z")

</div>

Never mind, I managed to solve it using the wait block 🙂

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [June 15, 2021, 3:49pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/11 "2021-06-15T15:49:00Z")

</div>

The burble `Get` block for the database is **asynchronous** which means it will not half the app until the operation is completed but will take the requested operation and allow the app to continue processing next block.

This means your alert block will execute before the realtime\_DB Get is completed and therefore you might not see any values in the alert message.

If you insert a `wait` block before getting the length of the list you will give time to the `Get` block to execute and provide you with results.

Hope it is clear now.

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:20pm UTC](https://community.thunkable.com/t/solved-problem-with-length-of-list-block/1346419/12 "2024-11-08T13:20:18Z")

</div>


