# For loop that references two different arrays

**URL:** <https://discourse.julialang.org/t/for-loop-that-references-two-different-arrays/14782>\
**Category:** New to Julia\
**Tags:** array\
**Created:** [September 10, 2018, 8:39pm UTC](https://discourse.julialang.org/t/for-loop-that-references-two-different-arrays/14782 "2018-09-10T20:39:17Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 11, 2018, 8:30pm UTC](https://discourse.julialang.org/t/for-loop-that-references-two-different-arrays/14782/7 "2018-09-11T20:30:09Z")

</div>

> [@Seif\_Shebl](#):
>
> ```julia
> x = 0:99
> xhat = mean(x)
> xminxhat = collect(x .- xhat)
> 
> ```

Do you even need to collect the last vector? This is more than 3x faster again:

```julia
x = 0:99
xhat = mean(x)
xminxhat = x .- xhat

```

---

_[View the full topic](https://discourse.julialang.org/t/for-loop-that-references-two-different-arrays/14782)._
