# Looping over each index in varargs

**URL:** <https://discourse.julialang.org/t/looping-over-each-index-in-varargs/78200>\
**Category:** General Usage\
**Tags:** question, function, iterators\
**Created:** [March 21, 2022, 8:20am UTC](https://discourse.julialang.org/t/looping-over-each-index-in-varargs/78200 "2022-03-21T08:20:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [March 21, 2022, 8:20am UTC](https://discourse.julialang.org/t/looping-over-each-index-in-varargs/78200/1 "2022-03-21T08:20:14Z")

</div>

I have a function that takes in any number of vectors, not necessarily of equal length:

```julia
function exfnc(x::Vector{Float64}...)
    sizes = length.(x)
    ## compute some function over all combinations (x1[i], x2[j], ..., xn[k])?
end

```

Say there are `n` such vectors and I have some function that takes in this `n`-vector. I want to compute this function over all possible combinations of the elements between each vector. For example, if I only had to consider three arguments, I could write something like:

```julia
function exfnc(x₁, x₂, x₃)
    for k in eachindex(x₃)
        for j in eachindex(x₂)
            for i in eachindex(x₁)
                val = f(x₁[i], x₂[j], x₃[k]) # some function f
                # do something with val...
            end
        end
    end
end

```

Is there a way to form this type of loop for the `Varargs` case?

---

<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:** [March 21, 2022, 8:43am UTC](https://discourse.julialang.org/t/looping-over-each-index-in-varargs/78200/2 "2022-03-21T08:43:57Z")

</div>

Perhaps you want `Iterators.product`?

```julia
function exfnc(x...)
    for p in Iterators.product(x...)
        val = f(p...) # some function f
        # do something with val...
    end
end

```
