# Iterate thru lists with While Loop in Code Block

**URL:** <https://forum.dynamobim.com/t/iterate-thru-lists-with-while-loop-in-code-block/38728>\
**Category:** DesignScript\
**Tags:** revit, loop, dynamo\
**Created:** [July 25, 2019, 6:02pm UTC](https://forum.dynamobim.com/t/iterate-thru-lists-with-while-loop-in-code-block/38728 "2019-07-25T18:02:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AverageG](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@AverageG](https://forum.dynamobim.com/u/AverageG)\
**Post date:** [July 25, 2019, 6:02pm UTC](https://forum.dynamobim.com/t/iterate-thru-lists-with-while-loop-in-code-block/38728/1 "2019-07-25T18:02:56Z")

</div>

Hello,

Can some one please tell me what is wrong with this loop? It appears like it’s not going thru the list iterations at all if I get the return value of i to be 0.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/6/36ff99c3bc497f4239294e25d4b6efa7382080c7.png)

---

<div class="post-metadata">

**Author:** ![khuzaimah.ElecEng](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/khuzaimah.eleceng/32/92768_2.png) [@khuzaimah.ElecEng](https://forum.dynamobim.com/u/khuzaimah.ElecEng)\
**Post date:** [July 25, 2019, 6:06pm UTC](https://forum.dynamobim.com/t/iterate-thru-lists-with-while-loop-in-code-block/38728/2 "2019-07-25T18:06:17Z")

</div>

i suggest to assign Imperative to a variable like

val=[Imperative]

also the return must be written before the last bracket “}”  
the after the bracket write the output  
val

---

<div class="post-metadata">

**Author:** ![AverageG](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@AverageG](https://forum.dynamobim.com/u/AverageG)\
**Post date:** [July 25, 2019, 6:14pm UTC](https://forum.dynamobim.com/t/iterate-thru-lists-with-while-loop-in-code-block/38728/3 "2019-07-25T18:14:10Z")

</div>

Wow thank you so much! I got the increment to work! However, for some reasons I still can’t get and set parameter within the inner while loop. But maybe that’s another problem.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/4/24ff6d65dc0154fef557dfc08d9e4851e9ac0be9.png)
