# TIL: loop variables can be an element of an array, dict, etc

**URL:** <https://discourse.julialang.org/t/til-loop-variables-can-be-an-element-of-an-array-dict-etc/120840>\
**Category:** General Usage\
**Created:** [October 3, 2024, 6:30am UTC](https://discourse.julialang.org/t/til-loop-variables-can-be-an-element-of-an-array-dict-etc/120840 "2024-10-03T06:30:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![screw\_dog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/screw_dog/32/48119_2.png) [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Post date:** [October 3, 2024, 6:30am UTC](https://discourse.julialang.org/t/til-loop-variables-can-be-an-element-of-an-array-dict-etc/120840/1 "2024-10-03T06:30:17Z")

</div>

Been using Julia for several years and only just realised that you can use elements of an array, dict, etc as a loop variable. Eg

```julia
julia> v = zeros(Int, 3); for v[1] ∈ 0:3, v[2] ∈ v[1]:3, v[3] ∈ v[2]:3
         println(v)
       end
[0, 0, 0]
[0, 0, 1]
[0, 0, 2]
[0, 0, 3]
[0, 1, 1]
[0, 1, 2]
[0, 1, 3]
[0, 2, 2]
[0, 2, 3]
[0, 3, 3]
[1, 1, 1]
[1, 1, 2]
[1, 1, 3]
[1, 2, 2]
[1, 2, 3]
[1, 3, 3]
[2, 2, 2]
[2, 2, 3]
[2, 3, 3]
[3, 3, 3]

```

Not a big deal but kinda neat

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 3, 2024, 6:46am UTC](https://discourse.julialang.org/t/til-loop-variables-can-be-an-element-of-an-array-dict-etc/120840/2 "2024-10-03T06:46:46Z")

</div>

Also works for properties (dots, `setproperty!` shows up in `Meta.@lower`). This isn’t documented so I’m tentatively considering this an unstable lowering quirk.
