# Where Statements

**URL:** <https://discourse.julialang.org/t/where-statements/10442>\
**Category:** General Usage\
**Created:** [April 19, 2018, 5:32pm UTC](https://discourse.julialang.org/t/where-statements/10442 "2018-04-19T17:32:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [April 19, 2018, 5:32pm UTC](https://discourse.julialang.org/t/where-statements/10442/1 "2018-04-19T17:32:16Z")

</div>

I would like to understand the difference between multiple where statements and single where statement.

Can someone point me in the right direction or give me good answer?

Here is an example:

```nohighlight
julia> function foo(x::T,y::U) where {T<:Real,U<:T}
           x+y
       end
foo (generic function with 1 method)

function tar(x::T,y::U) where U<:T where T<:Real
           x+y
       end

julia> function bar(x::T,y::U) where T<:Real where U<:T
           x+y
       end
ERROR: UndefVarError: T not defined

```

---

<div class="post-metadata">

**Author:** ![ntezak](https://avatars.discourse-cdn.com/v4/letter/n/8797f3/32.png) [@ntezak](https://discourse.julialang.org/u/ntezak)\
**Post date:** [April 19, 2018, 6:36pm UTC](https://discourse.julialang.org/t/where-statements/10442/2 "2018-04-19T18:36:32Z")

</div>

It is instructive to look what the parser turns your different variants into:

```julia
julia> :(function bar(x::T,y::U) where T<:Real where U<:T
                  x+y
              end)
:(function (bar(x::T, y::U) where T <: Real) where U <: T # REPL[7], line 2:
        x + y
    end)

```

This shows that each `where` statement creates a new level of nesting and in particular `T` here is only defined inside the inner nesting level, therefore you cannot reference it in the outer where statement.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [April 19, 2018, 6:43pm UTC](https://discourse.julialang.org/t/where-statements/10442/3 "2018-04-19T18:43:01Z")

</div>

My advice is that, in order to avoid confusion for yourself and others reading your code, you should avoid using nested `where` statements. It should almost never be necessary.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 20, 2018, 2:38pm UTC](https://discourse.julialang.org/t/where-statements/10442/4 "2018-04-20T14:38:36Z")

</div>

```julia
where {T<:Real, U<:T}

```

is equivalent to

```julia
where U<:T where T<:Real

```

in other words, the nesting order is reversed.
