# Problems Looping an array, Read on for more info.

**URL:** <https://forums.unrealengine.com/t/problems-looping-an-array-read-on-for-more-info/424097>\
**Category:** UI\
**Tags:** unreal-engine, Array, Widget, question, UMG\
**Created:** [May 1, 2018, 7:59pm UTC](https://forums.unrealengine.com/t/problems-looping-an-array-read-on-for-more-info/424097 "2018-05-01T19:59:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ikaruza](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ikaruza](https://forums.unrealengine.com/u/Ikaruza)\
**Post date:** [May 1, 2018, 7:59pm UTC](https://forums.unrealengine.com/t/problems-looping-an-array-read-on-for-more-info/424097/1 "2018-05-01T19:59:47Z")

</div>

So i’ve been working on this for a while, and have gotten to a point where i can’t figure it out, I’m attempting to loop an array, so that, if the current index is equal to the length of the array, it returns 0 instead of the length (which results in an error cause 8 length array only goes from 0-7) and the reverse, if index is less than 0, then return length of array -1 (again cause setting it to length would be 8 again) I have made a macro for this which i’m about 90% sure is working correctly, but i’m still getting errors such as “Tried to get index -1 from array” etc, the adding one works but the other does not, if you can spot the problem in the Screenshots below, it would be very very much appreciated.  
Thanks in advance.

Index Loop Macro

 ![239517-ue4editor-2018-05-01-20-50-54.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/7/5/575091005730c030194516daead893dcd747cf1c.png)

Widget Position Array Lerp (Don’t think this works but adding anyway cause its in there)

 ![239518-ue4editor-2018-05-01-20-51-26.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/2/e628e64cc2cd1663860a87bbf13c1f3528189eb7.png)

Widget Blueprint Itself

 ![239519-ue4editor-2018-05-01-20-56-48.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/e/f5e41aa0a7e5fbe7d13bd8760ea93874b317548c.png)

Again, thanks in advance for any light you may shed on this situation.

P.S. The ReverseForEachLoop worked better as a regular ForEachLoop but i was trying it out when i took the screenshot.

---

<div class="post-metadata">

**Author:** ![goncasmage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@goncasmage](https://forums.unrealengine.com/u/goncasmage)\
**Post date:** [May 1, 2018, 8:04pm UTC](https://forums.unrealengine.com/t/problems-looping-an-array-read-on-for-more-info/424097/2 "2018-05-01T20:04:49Z")

</div>

When you’re traversing an array, the index will at most be the length of the array - 1. Try changing the condition in your first screenshot to “\<=” instead of “\<” !
