I’ve just stumbled across something odd when using a nested for statement in a generator expression. I would have expected collect((n,k) for n in 1:5, k in 1:n)
to be equivalent to collect((n,k) for n in 1:5 for k in 1:n)
, just like
for n in 1:5, k in 1:n
...
end
is the same as
for n in 1:5
for k in 1:n
...
end
end
Instead, the single for statement produces the full 5x5 matrix of (n,k) combinations (equivalent to collect((n,k) for n in 1:5, k in 1:5)
) whereas the explicit double for statement produces only the pairs with k <= n (as expected).
Am I missing something here? I this done on purpose or a bug? I don’t find the behavior very intuitive. This is using Julia 1.7.1.