# Nested While loop in a For loop

**URL:** <https://forum.dynamobim.com/t/nested-while-loop-in-a-for-loop/82870>\
**Category:** DesignScript\
**Created:** [November 8, 2022, 6:10pm UTC](https://forum.dynamobim.com/t/nested-while-loop-in-a-for-loop/82870 "2022-11-08T18:10:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas.B](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nicolas.B](https://forum.dynamobim.com/u/Nicolas.B)\
**Post date:** [November 8, 2022, 6:10pm UTC](https://forum.dynamobim.com/t/nested-while-loop-in-a-for-loop/82870/1 "2022-11-08T18:10:19Z")

</div>

Good day!  
I have an input list - no.1 which will be turn out to output list - no.2. And i want to achieve that result by using Imperative block. i try with t0 and it work, but no chance for t1 which is a nested while loop in a for loop.  
Could you help me to figure it out?  
Any help will be appriciated!  
Thank you!

 ![nestedloop](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/e/9e3ee8df4674932bfe4aec28e3058bc40daec2fa.png)

---

<div class="post-metadata">

**Author:** ![Meychik](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@Meychik](https://forum.dynamobim.com/u/Meychik)\
**Post date:** [November 9, 2022, 7:56am UTC](https://forum.dynamobim.com/t/nested-while-loop-in-a-for-loop/82870/2 "2022-11-09T07:56:09Z")

</div>

Hi @Nicolas.B

here you are trying to itterate through a number and not a list (an array). You need to adjust slightly the first loop like this.

```auto
for (i in 0..count1 - 1)

```

I also don’t fully understand why using this to put everything into an additonal list when you have already a list with everything you need after execution.

```auto
t2 = List.AddItemToEnd(tem_t2, t2);

```

and delete this to avoid quiting the loop after the first itteration

```auto
return t1;

```

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/b/3b6991508ff9f365c0b8a8cd1424e80ba63d8044.png)

---

<div class="post-metadata">

**Author:** ![Nicolas.B](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nicolas.B](https://forum.dynamobim.com/u/Nicolas.B)\
**Post date:** [November 9, 2022, 8:11am UTC](https://forum.dynamobim.com/t/nested-while-loop-in-a-for-loop/82870/3 "2022-11-09T08:11:03Z")

</div>

thank you very much, Meychik!  
i was wrong when itterate a number (i in count), it should be: for (i in lst) or for (i in 0…count1 - 1) as you pointed out.

 ![nestedloop2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/0/a01f35f01347c25a920c029d33c087854923ce69.png)
