# Is there a concise way to express "\[println(i, j) for i = 1 : j, j = 1:3\]"

**URL:** <https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073>\
**Category:** New to Julia\
**Created:** [June 2, 2024, 12:25am UTC](https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073 "2024-06-02T00:25:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lionisxn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lionisxn/32/37989_2.png) [@lionisxn](https://discourse.julialang.org/u/lionisxn)\
**Post date:** [June 2, 2024, 12:25am UTC](https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073/1 "2024-06-02T00:25:08Z")

</div>

Hi, is there a concise way to express the “for” circulation like “[println(i, j) for i = 1 : j, j = 1:3]”, I encounter the “ERROR: UndefVarError: `j` not defined”. I thought such an expression is more concise than

> for j = 1:3, i = 1:j  
> println(i, j)  
> end

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [June 2, 2024, 12:43am UTC](https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073/2 "2024-06-02T00:43:24Z")

</div>

Maybe

```julia
julia> [println(i, j) for j in 1:3 for i in 1:j];
11
12
22
13
23
33

```

Note the `;` to drop the wastefully generated vector.

Or:

```julia
julia> foreach(splat(println),((i,j) for j in 1:3 for i in 1:j))
11
12
22
13
23
33

```

with less waste.

---

<div class="post-metadata">

**Author:** ![lionisxn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lionisxn/32/37989_2.png) [@lionisxn](https://discourse.julialang.org/u/lionisxn)\
**Post date:** [June 2, 2024, 12:47am UTC](https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073/3 "2024-06-02T00:47:00Z")

</div>

thank you, Dan! I just found the comma between “j in 1:3” and “i in 1:j” in my code should be replaced with “for”!

---

<div class="post-metadata">

**Author:** ![lionisxn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lionisxn/32/37989_2.png) [@lionisxn](https://discourse.julialang.org/u/lionisxn)\
**Post date:** [June 2, 2024, 12:52am UTC](https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073/4 "2024-06-02T00:52:36Z")

</div>

I just tied “[println(i, j) for j in 1:3, i in 1:3]” and it worked, astonishing!

---

<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:** [June 2, 2024, 3:09am UTC](https://discourse.julialang.org/t/is-there-a-concise-way-to-express-println-i-j-for-i-1-j-j-1-3/115073/5 "2024-06-02T03:09:37Z")

</div>

If you really don’t need the output vector, `for j = 1:3, i = 1:j println(i, j) end` in one line works and is shorter than that array comprehension, newlines aren’t needed for most blocks (I almost said all but off the top of my head, `let`’s header is an exception) and can be replaced with `;` if needed.
