# Like a list comprehension but with several lines

**URL:** <https://discourse.julialang.org/t/like-a-list-comprehension-but-with-several-lines/95365>\
**Category:** General Usage\
**Created:** [March 1, 2023, 3:53am UTC](https://discourse.julialang.org/t/like-a-list-comprehension-but-with-several-lines/95365 "2023-03-01T03:53:37Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)\
**Post date:** [March 1, 2023, 7:46am UTC](https://discourse.julialang.org/t/like-a-list-comprehension-but-with-several-lines/95365/5 "2023-03-01T07:46:25Z")

</div>

Hello Gus!

I was pondering a similar problem when I posted [this suggestion](https://discourse.julialang.org/t/proposal-to-extend-the-syntax-of-list-comprehensions-with-a-let-clause). Based on [this answer](https://discourse.julialang.org/t/proposal-to-extend-the-syntax-of-list-comprehensions-with-a-let-clause/87256/9), your contrived loop can be rewritten in list comprehension syntax as follows:

```plaintext
out = [rand(s)[1]
       for i in 10:2:30
       for t = Ref(randperm(i))
       for s = Ref(maximum(t))]

```

Whether you prefer this, the for loop or the map syntax is a matter of taste.

HTH.

---

_[View the full topic](https://discourse.julialang.org/t/like-a-list-comprehension-but-with-several-lines/95365)._
