# A switch type function

**URL:** <https://discourse.julialang.org/t/a-switch-type-function/13491>\
**Category:** New to Julia\
**Tags:** control-flow\
**Created:** [August 15, 2018, 8:45am UTC](https://discourse.julialang.org/t/a-switch-type-function/13491 "2018-08-15T08:45:57Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 9, 2021, 8:13pm UTC](https://discourse.julialang.org/t/a-switch-type-function/13491/15 "2021-08-09T20:13:09Z")

</div>

Less verbose (and builtin) is chained ternaries. With indentation they can be quite readable for short expressions like these:

```julia
n = 1.0
m = n ≤ 0.1 ? 0.0 :
    0.1 < n ≤ 0.6 ? 1.0 :
    0.6 < n ≤ 0.8 ? 1.1 :
    0.8 < n ≤ 1.0 ? 1.2 :
    1.0 < n ≤ 1.3 ? 1.35 :
    #= otherwise =# 2.2

```

---

_[View the full topic](https://discourse.julialang.org/t/a-switch-type-function/13491)._
