# How to prevent type instability in for loops?

**URL:** <https://discourse.julialang.org/t/how-to-prevent-type-instability-in-for-loops/30508>\
**Category:** Performance\
**Tags:** question\
**Created:** [October 30, 2019, 6:11pm UTC](https://discourse.julialang.org/t/how-to-prevent-type-instability-in-for-loops/30508 "2019-10-30T18:11:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [October 30, 2019, 6:24pm UTC](https://discourse.julialang.org/t/how-to-prevent-type-instability-in-for-loops/30508/2 "2019-10-30T18:24:18Z")

</div>

AFAIU, this “type instability” is harmless. It is a consequence of the [iterator interface](https://docs.julialang.org/en/latest/manual/interfaces/#) which returns `nothing` when the end of the iterator is reached. Note that the line you cited from the `@code_warntype` output is colored in yellow (not red, which indicates “true” type instabilities).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-prevent-type-instability-in-for-loops/30508)._
