# How to loop through containers in script module

**URL:** <https://forum.inductiveautomation.com/t/how-to-loop-through-containers-in-script-module/3255>\
**Category:** Ignition\
**Created:** [September 6, 2011, 7:45pm UTC](https://forum.inductiveautomation.com/t/how-to-loop-through-containers-in-script-module/3255 "2011-09-06T19:45:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brett\_Yeomans](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brett\_Yeomans](https://forum.inductiveautomation.com/u/Brett_Yeomans)\
**Post date:** [September 6, 2011, 7:45pm UTC](https://forum.inductiveautomation.com/t/how-to-loop-through-containers-in-script-module/3255/1 "2011-09-06T19:45:56Z")

</div>

I have a script module that builds an SQL query based on “isPropertyDefined” that works ok but I want to loop the script x amount of times each time checking a different container. What I cannot solve is how to change from one container to the next. The script has the following:

cont = event.source.parent.getComponent(“1”)  
This works ok but I want to change this on each loop to:

cont = event.source.parent.getComponent(“1”)  
cont = event.source.parent.getComponent(“2”)  
cont = event.source.parent.getComponent(“3”) …etc

If I put in:

i +=1  
cont = event.source.parent.getComponent(i)

it fails as does:

i +=1  
j = “”" + str(i)+"""  
cont = event.source.parent.getComponent(j)

What am I doing wrong???

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 6, 2011, 7:47pm UTC](https://forum.inductiveautomation.com/t/how-to-loop-through-containers-in-script-module/3255/2 "2011-09-06T19:47:58Z")

</div>

You just need to do the following:`i +=1 
cont = event.source.parent.getComponent(str(i))`
