# For Each loop causing infinite loop?

**URL:** <https://forums.unrealengine.com/t/for-each-loop-causing-infinite-loop/465691>\
**Category:** Platform & Builds\
**Tags:** while-loop, infinite-loop, unreal-engine, question\
**Created:** [May 24, 2020, 12:11am UTC](https://forums.unrealengine.com/t/for-each-loop-causing-infinite-loop/465691 "2020-05-24T00:11:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_0efb4f1d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0efb4f1d](https://forums.unrealengine.com/u/anonymous_user_0efb4f1d)\
**Post date:** [May 24, 2020, 12:11am UTC](https://forums.unrealengine.com/t/for-each-loop-causing-infinite-loop/465691/1 "2020-05-24T00:11:43Z")

</div>

Hi all,

I am having a relatively straightforward problem. I am running a while loop with nested for each loops. The while loop is dependent on the number of iterations of these for each loops. Appending to these for each loops within the while loops is causing an infinite loop crash. See below:

 ![302590-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/e/96e4faca008fed204cf771a290d5cf6a6d63d3f6.png)

This is the only place I edit the array for the for each loops. it is outside and of the for each loops themselves. I know this is the error because if I remove the append the code compiles and runs.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 24, 2020, 7:55am UTC](https://forums.unrealengine.com/t/for-each-loop-causing-infinite-loop/465691/2 "2020-05-24T07:55:29Z")

</div>

Where do you decrease the _RoomCount_?
