# Too many levels of nested for loops

**URL:** <https://discourse.julialang.org/t/too-many-levels-of-nested-for-loops/56335>\
**Category:** General Usage\
**Created:** [March 2, 2021, 2:32pm UTC](https://discourse.julialang.org/t/too-many-levels-of-nested-for-loops/56335 "2021-03-02T14:32:17Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![MarcMush](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcmush/32/18006_2.png) [@MarcMush](https://discourse.julialang.org/u/MarcMush)\
**Post date:** [March 4, 2021, 3:14pm UTC](https://discourse.julialang.org/t/too-many-levels-of-nested-for-loops/56335/4 "2021-03-04T15:14:04Z")

</div>

you can use `Iterators.product`:

```julia
s = 0
for (i1,i2,i3,i4) in Iterators.product(1:4, 1:4, 1:4, 1:4)
    s += i1 + i2 + i3 + i4
end
s

```

or with an arbitrary number of nested loops:

```julia
N = 4
s = 0
for i in Iterators.product(fill(1:4, N)...)
    s += sum(i)
end
s

```

---

_[View the full topic](https://discourse.julialang.org/t/too-many-levels-of-nested-for-loops/56335)._
