# Nested Ranges in Generator

**URL:** <https://discourse.julialang.org/t/nested-ranges-in-generator/26268>\
**Category:** General Usage\
**Created:** [July 12, 2019, 1:52am UTC](https://discourse.julialang.org/t/nested-ranges-in-generator/26268 "2019-07-12T01:52:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![milesf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milesf/32/9289_2.png) [@milesf](https://discourse.julialang.org/u/milesf)\
**Post date:** [July 12, 2019, 1:52am UTC](https://discourse.julialang.org/t/nested-ranges-in-generator/26268/1 "2019-07-12T01:52:34Z")

</div>

What is the generator syntax where the value of variables from one range can be used as limits for another range?

```julia
collect([a,b] for a=1:2, b=a:a+1)
ERROR: UndefVarError: a not defined

```

Expecting

```julia
 [1, 1] [1, 2]
 [2, 2] [2, 3]

```

Here’s an example where `b` does not depend on `a`.

```julia
collect([a,b] for a=1:2, b=4:5)
2×2 Array{Array{Int64,1},2}:
 [1, 4] [1, 5]
 [2, 4] [2, 5]

```

---

<div class="post-metadata">

**Author:** ![wookyoung](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wookyoung/32/157_2.png) [@wookyoung](https://discourse.julialang.org/u/wookyoung)\
**Post date:** [July 12, 2019, 2:50am UTC](https://discourse.julialang.org/t/nested-ranges-in-generator/26268/2 "2019-07-12T02:50:35Z")

</div>

welcome to discourse 🙂

see [Single- and multi-dimensional Arrays · The Julia Language](https://docs.julialang.org/en/v1/manual/arrays/#Generator-Expressions-1)

> Ranges in generators and comprehensions can depend on previous ranges by writing multiple `for` keywords

```julia
julia> collect([a,b] for a=1:2 for b=a:a+1)
4-element Array{Array{Int64,1},1}:
 [1, 1]
 [1, 2]
 [2, 2]
 [2, 3]

```
