# ForwardIterator Method

**URL:** <https://forum.dynamobim.com/t/forwarditerator-method/17550>\
**Category:** Lists-Logic\
**Tags:** python\
**Created:** [December 20, 2017, 6:51am UTC](https://forum.dynamobim.com/t/forwarditerator-method/17550 "2017-12-20T06:51:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![til.shviger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/til.shviger/32/36048_2.png) [@til.shviger](https://forum.dynamobim.com/u/til.shviger)\
**Post date:** [December 20, 2017, 6:51am UTC](https://forum.dynamobim.com/t/forwarditerator-method/17550/1 "2017-12-20T06:51:29Z")

</div>

Hello  
please explain to me when to apply and what is **ForwardIterator Method()**  
from RevitAPI:

> **[ForwardIterator Method](https://www.revitapidocs.com/2017.1/663d1a29-b38d-b3e6-e7f5-7b5e6a901713.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

for example here

> con\_set=[i.ConnectorManager.Connectors.ForwardIterator() for i in pipes]

I want to understand for what purposes I can use it

---

<div class="post-metadata">

**Author:** ![haganjake2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/haganjake2/32/119069_2.png) [@haganjake2](https://forum.dynamobim.com/u/haganjake2)\
**Post date:** [June 17, 2022, 9:23am UTC](https://forum.dynamobim.com/t/forwarditerator-method/17550/2 "2022-06-17T09:23:25Z")

</div>

Any forward iterator know it all’s able to answer this?

Trying to decipher the code on this page ([Set parameter of multiple family types in .RFA-file with python - #2 by blsalvio](https://forum.dynamobim.com/t/set-parameter-of-multiple-family-types-in-rfa-file-with-python/60486/2)) and am scared to run a while loop without knowing what the forward iteration really is!

```auto
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

param_values = list()
types = doc.FamilyManager.Types
famMan = doc.FamilyManager

TransactionManager.Instance.EnsureInTransaction(doc)

familyTypesItor = famMan.Types.ForwardIterator()
familyTypesItor.Reset()

while (familyTypesItor.MoveNext()):
    familyType = familyTypesItor.Current
    familyParam = famMan.get_Parameter(IN[0])
    param_values.append(familyType.AsString(familyParam))
    famMan.CurrentType = familyType
    famMan.Set(familyParam, IN[1] + familyType.AsString(familyParam))

TransactionManager.Instance.TransactionTaskDone()

OUT = param_values

```

Thanks,  
Jake

---

<div class="post-metadata">

**Author:** ![stewart.skyler](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@stewart.skyler](https://forum.dynamobim.com/u/stewart.skyler)\
**Post date:** [June 21, 2022, 10:12pm UTC](https://forum.dynamobim.com/t/forwarditerator-method/17550/3 "2022-06-21T22:12:29Z")

</div>

An iterator is a method that allows you to step through a data set, like a list, one object at a time.  
In your specific instance, `famMan.Types` calls a [FamilyTypeSet](https://www.revitapidocs.com/2022/e9c3b1c1-3033-ec43-3406-f2e3d5276edb.htm), the [ForwardIterator()](https://www.revitapidocs.com/2022/fc8efada-122c-e709-9b60-cd748a4f5fef.htm) method then calls up a [FamilyTypeSetIterator](https://www.revitapidocs.com/2022/fc8efada-122c-e709-9b60-cd748a4f5fef.htm). If you look at the methods here, there is a `.MoveNext()` but no `.MoveBack()`. If we go back to the FamilyTypeSet page, you can see there is also a [ReverseIterator()](https://www.revitapidocs.com/2022/39c6ba67-1469-a905-ae18-aaaa1bc615ea.htm) method. However, `ReverseIterator()` is also a `FamilyTypeSetIterator`, so it also only has a `MoveNext()`.

What this means, is that `ForwardIterator()` and `ReverseIterator()` are used tell the code which direction you’re moving through the list when you call `.MoveNext()`.

You’re code looks fine - once `MoveNext()` reaches the end it will return False.  
That said, at least during testing it’s never a bad idea to add a safety exit.

```auto
exit_variable = 0
while ____ and exit_variable < 1000:
    exit_variable += 1
    #The rest of your code goes here
```

---

<div class="post-metadata">

**Author:** ![haganjake2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/haganjake2/32/119069_2.png) [@haganjake2](https://forum.dynamobim.com/u/haganjake2)\
**Post date:** [June 29, 2022, 11:36am UTC](https://forum.dynamobim.com/t/forwarditerator-method/17550/4 "2022-06-29T11:36:20Z")

</div>

Thanks for your explanation! Makes a lot more sense now and also a great trick to try and avoid the dreaded infinite loop!

Thanks
