# Is while loop is cheaper than for loop?

**URL:** <https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387>\
**Category:** Blueprint\
**Tags:** while-loop, for-loop, unreal-engine, Scripting, Blueprint, question\
**Created:** [September 12, 2017, 12:01pm UTC](https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387 "2017-09-12T12:01:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tokodboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tokodboy](https://forums.unrealengine.com/u/Tokodboy)\
**Post date:** [September 12, 2017, 12:01pm UTC](https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387/1 "2017-09-12T12:01:15Z")

</div>

I read that for loop is an expensive operation because Loop iterations will take place between frames, so large loops may incur a performance hit.

But what the matter with the While Loop? It is faster/cheaper then for?

Thx: Viktor

---

<div class="post-metadata">

**Author:** ![ZkarmaKun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zkarmakun/32/1194545_2.png) [@ZkarmaKun](https://forums.unrealengine.com/u/ZkarmaKun)\
**Post date:** [September 12, 2017, 2:00pm UTC](https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387/2 "2017-09-12T14:00:26Z")

</div>

Any compiler will generate practically identical byte code, Any difference in performance is negligible, that question is really old, and is called micro-optimizing,

Perhaps you can consider what is more human readable for you!

Another history is usability, meanwhile “For” is just a iterator, “while” is bit more flexible, is meant to find solutions through iterations.

Hope this answer your question

---

<div class="post-metadata">

**Author:** ![Grimwolf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grimwolf](https://forums.unrealengine.com/u/Grimwolf)\
**Post date:** [September 12, 2017, 2:15pm UTC](https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387/3 "2017-09-12T14:15:12Z")

</div>

Assuming they run for the same number of loops, the performance should be effectively identical. They perform basically the same function, they just use different criteria for when they should stop.

---

<div class="post-metadata">

**Author:** ![Tokodboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tokodboy](https://forums.unrealengine.com/u/Tokodboy)\
**Post date:** [September 13, 2017, 6:38am UTC](https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387/4 "2017-09-13T06:38:28Z")

</div>

Thanks to everyone. Unfortunately blueprints can’t handle large loops effectively.

---

<div class="post-metadata">

**Author:** ![Tokodboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tokodboy](https://forums.unrealengine.com/u/Tokodboy)\
**Post date:** [September 13, 2017, 6:38am UTC](https://forums.unrealengine.com/t/is-while-loop-is-cheaper-than-for-loop/404387/5 "2017-09-13T06:38:53Z")

</div>

Thanks to everyone. Unfortunately blueprints can’t handle large loops effectively.
