# Best way to loop over arrays sequentially?

**URL:** <https://discourse.julialang.org/t/best-way-to-loop-over-arrays-sequentially/6363>\
**Category:** General Usage\
**Created:** [October 9, 2017, 8:38pm UTC](https://discourse.julialang.org/t/best-way-to-loop-over-arrays-sequentially/6363 "2017-10-09T20:38:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [October 9, 2017, 8:38pm UTC](https://discourse.julialang.org/t/best-way-to-loop-over-arrays-sequentially/6363/1 "2017-10-09T20:38:17Z")

</div>

For example, if you had:

```julia
x_vars = ["T_k", "Q", "kappa", "delta", "epsilon", "wave_theta"]

y_vars = ["R_0", "B_0", "P_F", "eta_CD", "rho_j", "f_B", "n_bar", "I_M"]

for cur_var in vcat(x_vars, y_vars)
    println(cur_var)
end

```

Whats the most efficient way to handle the `vcat` behavior as:

- `x_vars` & `y_vars` become large
- the list of vars becomes longer (i.e. if there were `z_vars` and `w_vars`)

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 9, 2017, 8:41pm UTC](https://discourse.julialang.org/t/best-way-to-loop-over-arrays-sequentially/6363/2 "2017-10-09T20:41:13Z")

</div>

How about `IterTools.chain`?

---

<div class="post-metadata">

**Author:** ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)\
**Post date:** [October 9, 2017, 9:22pm UTC](https://discourse.julialang.org/t/best-way-to-loop-over-arrays-sequentially/6363/3 "2017-10-09T21:22:25Z")

</div>

I don’t know if this is a naive solution, but the following works just fine:

```julia
x_vars = ["T_k", "Q", "kappa", "delta", "epsilon", "wave_theta"]

y_vars = ["R_0", "B_0", "P_F", "eta_CD", "rho_j", "f_B", "n_bar", "I_M"]

for x in (x_vars,y_vars), cur_var in x
    println(cur_var)
end

```
