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

#1

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> [(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 section, but what about the second and the third?

1 Like

#2

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

2 Likes

#3

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.

0 Likes

#4

Thanks for this I was looking for this last night…

0 Likes