# Any shortcut to 1:length(myVector)?

**URL:** <https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816>\
**Category:** General Usage\
**Created:** [January 4, 2021, 11:14am UTC](https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816 "2021-01-04T11:14:56Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [January 8, 2021, 6:07pm UTC](https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816/27 "2021-01-08T18:07:46Z")

</div>

Just go with:

`for value in container` – when you only care about iterating the values.  
`for index in eachindex(container)` – when you gonna just use the indexes, or the values are used very infrequently. EDIT: see below [1].  
`for (index, value) in pairs(container)` – when you gonna need both at each loop; or if you are using some more complex structure like `Dict`/trees and this may save some effort of hashing keys (or searching the tree) again.

[1] To complement: For simple code over `Vector`s there will probably no performance difference between `eachindex` + `container[index]` and `pairs`. If you gonna apply SSOT (Single Source of Truth) and you want to query the container every time instead of having bindings with cached values, then go for it. It may be better than using `pairs` in cases that, inside a single loop, the values may change inside the container and you always want to get the most recent values. But, theoretically, the performance of `pairs` will always be the same or better than `eachindex` + `container[index]` if both index and value are used.

---

_[View the full topic](https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816)._
