# Documentation for comprehensions with if and/or w/o comma

**URL:** <https://discourse.julialang.org/t/documentation-for-comprehensions-with-if-and-or-w-o-comma/23236>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 17, 2019, 11:22am UTC](https://discourse.julialang.org/t/documentation-for-comprehensions-with-if-and-or-w-o-comma/23236 "2019-04-17T11:22:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 17, 2019, 11:22am UTC](https://discourse.julialang.org/t/documentation-for-comprehensions-with-if-and-or-w-o-comma/23236/1 "2019-04-17T11:22:36Z")

</div>

I was about to refer a colleague the docs on the non-array form of comprehensions (with multiple `for`, optionally `if`), but I can’t find it. Eg in

```julia
julia> [(i = i, j = j) for i in 1:2, j in 1:3]
2×3 Array{NamedTuple{(:i, :j),Tuple{Int64,Int64}},2}:
 (i = 1, j = 1) (i = 1, j = 2) (i = 1, j = 3)
 (i = 2, j = 1) (i = 2, j = 2) (i = 2, j = 3)

julia> [(i = i, j = j) for i in 1:2 for j in 1:3]
6-element Array{NamedTuple{(:i, :j),Tuple{Int64,Int64}},1}:
 (i = 1, j = 1)
 (i = 1, j = 2)
 (i = 1, j = 3)
 (i = 2, j = 1)
 (i = 2, j = 2)
 (i = 2, j = 3)

julia> [(i = i, j = j) for i in 1:2 for j in 1:3 if j ≤ i]
3-element Array{NamedTuple{(:i, :j),Tuple{Int64,Int64}},1}:
 (i = 1, j = 1)
 (i = 2, j = 1)
 (i = 2, j = 2)

```

the first one is [documented in the Multi-dimensional Arrays](https://docs.julialang.org/en/v1.2-dev/manual/arrays/#Comprehensions-1) section, but what about the second and the third?

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [April 17, 2019, 11:39am UTC](https://discourse.julialang.org/t/documentation-for-comprehensions-with-if-and-or-w-o-comma/23236/2 "2019-04-17T11:39:53Z")

</div>

It’s a little further down, below “Generator Expressions”.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 17, 2019, 11:58am UTC](https://discourse.julialang.org/t/documentation-for-comprehensions-with-if-and-or-w-o-comma/23236/3 "2019-04-17T11:58:25Z")

</div>

Thanks, indeed it is. I was specifically looking for the explanation of the seemingly different traversal orders in the versions with and without the comma, and while it is documented, I guess clarification of this would not hurt.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [April 17, 2019, 12:11pm UTC](https://discourse.julialang.org/t/documentation-for-comprehensions-with-if-and-or-w-o-comma/23236/4 "2019-04-17T12:11:59Z")

</div>

Thanks for this I was looking for this last night…
