# I can not understand why Julia displays such results in chain comparisons?

**URL:** <https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 26, 2019, 2:00pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212 "2019-02-26T14:00:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![achitsaz](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@achitsaz](https://discourse.julialang.org/u/achitsaz)\
**Post date:** [February 26, 2019, 2:00pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/1 "2019-02-26T14:00:23Z")

</div>

Hello dear friends  
I can not understand why Julia displays the following result for the expression of chain comparisons:

```julia
julia> v(x) = (println(x); x)
v (generic function with 1 method)

julia> v(1) < v(3) <= v(4) < v(5) < v(10)
3
1
4
5
10
true

```

Why Julia does not show the following result:

```julia
julia> v(1) < v(3) <= v(4) < v(5) < v(10)
1
3
4
5
10
true

```

Hopefully I mean well. Tell me to explain more if I’m saying bad question.  
tnx:slightly\_smiling\_face:

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 26, 2019, 2:16pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/2 "2019-02-26T14:16:34Z")

</div>

Did you see:

[https://docs.julialang.org/en/v1/manual/mathematical-operations/index.html#Chaining-comparisons-1](https://docs.julialang.org/en/v1/manual/mathematical-operations/index.html#Chaining-comparisons-1)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 26, 2019, 2:16pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/3 "2019-02-26T14:16:47Z")

</div>

This might make it a bit more clear how things are executed

```julia
julia> f() = v(1) < v(3) <= v(4) < v(5) < v(10);

julia> @code_lowered f()
CodeInfo(
1 ─ %1 = (Main.v)(3)
│ %2 = (Main.v)(1)
│ %3 = %2 < %1
└── goto #7 if not %3
2 ─ %5 = (Main.v)(4)
│ %6 = %1 <= %5
└── goto #6 if not %6
3 ─ %8 = (Main.v)(5)
│ %9 = %5 < %8
└── goto #5 if not %9
4 ─ %11 = (Main.v)(10)
│ %12 = %8 < %11
└── return %12
5 ─ return false
6 ─ return false
7 ─ return false
)

```

---

<div class="post-metadata">

**Author:** ![achitsaz](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@achitsaz](https://discourse.julialang.org/u/achitsaz)\
**Post date:** [February 26, 2019, 2:30pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/4 "2019-02-26T14:30:22Z")

</div>

yes i did, but i can’t understand.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 26, 2019, 2:36pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/5 "2019-02-26T14:36:49Z")

</div>

The compiler is free to rearrange the order to produce more efficient code, or for any other reason. As it says in the manual, the order is undefined, and you should not depend on it.

---

<div class="post-metadata">

**Author:** ![achitsaz](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@achitsaz](https://discourse.julialang.org/u/achitsaz)\
**Post date:** [February 26, 2019, 2:37pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/6 "2019-02-26T14:37:34Z")

</div>

I am very beginner and I do not understand anything from the code you wrote.🙄

---

<div class="post-metadata">

**Author:** ![achitsaz](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@achitsaz](https://discourse.julialang.org/u/achitsaz)\
**Post date:** [February 26, 2019, 2:41pm UTC](https://discourse.julialang.org/t/i-can-not-understand-why-julia-displays-such-results-in-chain-comparisons/21212/7 "2019-02-26T14:41:08Z")

</div>

> [@bennedich](#):
>
> The compiler is free to rearrange the order to produce more efficient code, or for any other reason. As it says in the manual, the order is undefined, and you should not depend on it.

Yes, I read that. But finally, the one who made Julia must know what’s going on. Is not it?
