# For Loop in Imperative Block

**URL:** <https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678>\
**Category:** Lists-Logic\
**Created:** [May 5, 2018, 3:54pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678 "2018-05-05T15:54:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Kraus](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Alexander\_Kraus](https://forum.dynamobim.com/u/Alexander_Kraus)\
**Post date:** [May 5, 2018, 3:54pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/1 "2018-05-05T15:54:02Z")

</div>

Why does this loop not work?  
Are for loops only possible within functions?  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/e/7ef90db58ca1c2b6c24edb9605d21707bb2fa932.png)

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [May 5, 2018, 4:08pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/2 "2018-05-05T16:08:12Z")

</div>

Return n, not numbers

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/5/75b23e5ea99e9607beda6592b8dc59182a2a799e.png)

What you’re actually doing is looping 30 times.

---

<div class="post-metadata">

**Author:** ![Alexander\_Kraus](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Alexander\_Kraus](https://forum.dynamobim.com/u/Alexander_Kraus)\
**Post date:** [May 5, 2018, 4:53pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/3 "2018-05-05T16:53:34Z")

</div>

Is that the solution?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/7/274d7e37e0524f7cc8c3e39c035112cc4771e685.png)

What is “number in numbers”? Is that 3 (listed) values or 31 values from [0] to [30]?

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [May 5, 2018, 4:58pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/4 "2018-05-05T16:58:29Z")

</div>

What is the desired output? Sure this is possible, but must admit my design script is not fantastic so would personally use Python nodes for loops as this 🙂

---

<div class="post-metadata">

**Author:** ![Alexander\_Kraus](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Alexander\_Kraus](https://forum.dynamobim.com/u/Alexander_Kraus)\
**Post date:** [May 5, 2018, 5:48pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/5 "2018-05-05T17:48:03Z")

</div>

I simply want to adress each item in a list [100,200,300] with the same operation, such as +100.

Later it should be used to calculate the distance between one point (point1) and each point in a list of points = [point1, point2, point3, …], so the result will be a list of distances.

---

<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:** [May 5, 2018, 6:30pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/6 "2018-05-05T18:30:10Z")

</div>

No need to get imperative here, design script has functionality to iterate over lists this simple in much simplistic manor. Just use the addition function directly.

`N+100;`

This will add 100 to every input.

If your math was more involved, the same thing applies:

`Math.Round(N+100)/12;`

The distance to question you had can be quickly set up by using the node to code functionality. Place a Geometry.DistanceTo node, wire it in with your points, select the node, right click the background and choose ‘node to code’ a s you’ll get the right solution for that as well.

---

<div class="post-metadata">

**Author:** ![Alexander\_Kraus](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Alexander\_Kraus](https://forum.dynamobim.com/u/Alexander_Kraus)\
**Post date:** [May 6, 2018, 5:07pm UTC](https://forum.dynamobim.com/t/for-loop-in-imperative-block/21678/7 "2018-05-06T17:07:16Z")

</div>

So iteration over lists looks simple in DS.  
Thanks.
