# Looping through Array but start at later Index. ForLoop vs ForEachLoop

**URL:** <https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184>\
**Category:** Blueprint\
**Tags:** engine-compile, unreal-engine, question, UE4-27\
**Created:** [March 1, 2022, 6:58pm UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184 "2022-03-01T18:58:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zvenzo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zvenzo](https://forums.unrealengine.com/u/Zvenzo)\
**Post date:** [March 1, 2022, 6:58pm UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184/1 "2022-03-01T18:58:08Z")

</div>

Hi,

I want to loop through my Array but I want to start at a later Index.  
My solutions, either go with a Forloop and define the start index, or use ForEachLoop and check each entry with a “Skipp me”? branch.  
Any real difference here with those 2 options? One more expensive than the other? You have a better idea for this?

 ![ForLoopVsForEachLoop](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/2/0221fc90cfa26207508b6b4be176cc571b8b784a.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![eldany.uy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eldany.uy/32/821920_2.png) [@eldany.uy](https://forums.unrealengine.com/u/eldany.uy)\
**Post date:** [March 1, 2022, 7:01pm UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184/2 "2022-03-01T19:01:27Z")

</div>

second looks more inefficient as you will always loop thru the whole array.

First one looks like the way to go! 🙂

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [March 3, 2022, 10:01pm UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184/3 "2022-03-03T22:01:18Z")

</div>

> [@eldany.uy](#):
>
> First one looks like the way to go! 🙂

Agreed.

Both versions are essentially same code. That get array element is also inside foreach loop. And you have additional condition there in foreach version of code. So extra check compared to top version.

However unless difference is for eg going trough 1000 items in for each vs doing only 900 to 1000 in first version i would pick what is more readable for me. Assuming here those loops are not nested inside other bigger loop.

But for me first version is more readable and it is faster.

---

<div class="post-metadata">

**Author:** ![midgunner66](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/midgunner66/32/466711_2.png) [@midgunner66](https://forums.unrealengine.com/u/midgunner66)\
**Post date:** [March 4, 2022, 4:47am UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184/4 "2022-03-04T04:47:11Z")

</div>

To answer your question, the first option is better.

Though, you can modify the for each loop to have a start index (make sure you duplicate it first to not affect the original):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/3/b03f797ff06c2ad03be02766fa26e1f2f0a08f33.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/3/a/93a17060db281a7cb193fb0f805aca402c418020.png)

---

<div class="post-metadata">

**Author:** ![Zvenzo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zvenzo](https://forums.unrealengine.com/u/Zvenzo)\
**Post date:** [March 4, 2022, 1:59pm UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184/5 "2022-03-04T13:59:52Z")

</div>

> That get array element is also inside foreach loop.

That was part of my concerns that lead to my question.  
Wonderful, thanks to you all for clearing this up. Appreciated!

---

<div class="post-metadata">

**Author:** ![araz01](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/araz01/32/1028814_2.png) [@araz01](https://forums.unrealengine.com/u/araz01)\
**Post date:** [May 12, 2024, 8:29pm UTC](https://forums.unrealengine.com/t/looping-through-array-but-start-at-later-index-forloop-vs-foreachloop/503184/6 "2024-05-12T20:29:25Z")

</div>

shii is so simple, you guys are silly for wasting my time.

 ![rotate_nearest_basic](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/f/f/dff45d4c2eaaf2bb46a14abe1648807dca161f00.png)
