# Using WhileLoop

**URL:** <https://forum.dynamobim.com/t/using-whileloop/91457>\
**Category:** Civil 3D\
**Tags:** loop, dynamo, looping\
**Created:** [July 5, 2023, 12:32pm UTC](https://forum.dynamobim.com/t/using-whileloop/91457 "2023-07-05T12:32:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maciej.wojtunik](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@maciej.wojtunik](https://forum.dynamobim.com/u/maciej.wojtunik)\
**Post date:** [July 5, 2023, 12:32pm UTC](https://forum.dynamobim.com/t/using-whileloop/91457/1 "2023-07-05T12:32:26Z")

</div>

Hello,  
I need to run a Function (green gruop) for each element in list (Data node on the beginning).  
I created such a WhileLoop, but it doesn’t work. The output is run the Function only for the last element .

 ![Numbering element based on Uniclass 2 _2023-07-05_03-26-38](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/e/fe22f65ae7466c1b09848422596701cab9d45090.png)

Does anyone had such problems with WhileLoop? Do You have any nice exapmle of usage of WhileLoop?  
Maybe there is a possiblity to do it with using a PythonScript Node?  
Thanks

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 5, 2023, 12:54pm UTC](https://forum.dynamobim.com/t/using-whileloop/91457/2 "2023-07-05T12:54:34Z")

</div>

Can’t read your nodes due to how the image was created. Zoom in so we can see clearly and export the image using the Export Canvas as Image tool (either a camera icon or ‘export’ text just outside the top right corner of the workspace).

90% of the time you don’t need a while loop to iterate over any items in Dynamo; the built in lacing provided by Dynamo’s associative language model should cover you as is.

The dynamo dictionary has a great example of this node in action here: [Dynamo Dictionary](https://dictionary.dynamobim.com/#/BuiltIn/Action/LoopWhile).

---

<div class="post-metadata">

**Author:** ![maciej.wojtunik](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@maciej.wojtunik](https://forum.dynamobim.com/u/maciej.wojtunik)\
**Post date:** [July 5, 2023, 1:27pm UTC](https://forum.dynamobim.com/t/using-whileloop/91457/3 "2023-07-05T13:27:23Z")

</div>

Thanks for reply.  
Well, In my view I want to connect each Element of list separately to green group, so I need to use loop. How lacing might help me?

 ![Numbering element based on Uniclass 2 _2023-07-05_03-26-38](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/e/fe22f65ae7466c1b09848422596701cab9d45090.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 5, 2023, 1:31pm UTC](https://forum.dynamobim.com/t/using-whileloop/91457/4 "2023-07-05T13:31:31Z")

</div>

> [@maciej.wojtunik](#):
>
> I want to connect each Element of list separately to green group

No need for the loop. Wire the list of property values directly into the propertyValue input of the ObjectByProperty node.

---

<div class="post-metadata">

**Author:** ![maciej.wojtunik](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@maciej.wojtunik](https://forum.dynamobim.com/u/maciej.wojtunik)\
**Post date:** [July 5, 2023, 2:00pm UTC](https://forum.dynamobim.com/t/using-whileloop/91457/5 "2023-07-05T14:00:01Z")

</div>

Thank You so much. I just connect the list and change lacing to Longest (in List.Count node) and then it works properly.
