# Programmatically iterate through all the controls located in a window

**URL:** <https://forum.inductiveautomation.com/t/programmatically-iterate-through-all-the-controls-located-in-a-window/14026>\
**Category:** Ignition\
**Created:** [April 12, 2017, 5:21am UTC](https://forum.inductiveautomation.com/t/programmatically-iterate-through-all-the-controls-located-in-a-window/14026 "2017-04-12T05:21:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 16, 2022, 9:57pm UTC](https://forum.inductiveautomation.com/t/programmatically-iterate-through-all-the-controls-located-in-a-window/14026/4 "2022-08-16T21:57:12Z")

</div>

Oy!

Recursion would be _ **SO** _ much easier to read.

Start with something like this:

```auto
#------------
# Recursively scan a container for children and the children's children, calling
# a given routine for each child encountered.
#
def forEachChild(container, func, lvl=None):
	if not lvl:
		lvl = 1
	func(container, lvl)
	for i in range(container.getComponentCount()):
		component = container.getComponent(i)
		forEachChild(component, func, lvl+1)

```

Pass it a function that takes a component and the depth as its parameters.

{ Note that this version enumerates the nested objects of regular components, too. }

---

_[View the full topic](https://forum.inductiveautomation.com/t/programmatically-iterate-through-all-the-controls-located-in-a-window/14026)._
