Best way to loop over arrays sequentially?

For example, if you had:

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)

How about IterTools.chain?

2 Likes

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

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
3 Likes