# Is there a "select case" equivalent in Julia?

**URL:** <https://discourse.julialang.org/t/is-there-a-select-case-equivalent-in-julia/66516>\
**Category:** General Usage\
**Tags:** fortran, control-flow\
**Created:** [August 16, 2021, 9:50pm UTC](https://discourse.julialang.org/t/is-there-a-select-case-equivalent-in-julia/66516 "2021-08-16T21:50:10Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [August 18, 2021, 4:35pm UTC](https://discourse.julialang.org/t/is-there-a-select-case-equivalent-in-julia/66516/22 "2021-08-18T16:35:27Z")

</div>

I purposefully didn’t use ternaries because the original Fortran example had cases with multiple statements. Sure you could use `begin ... end` there, but it erases any cleanliness benefits.

I haven’t verified whether your snippet or any of the ones below generate a switch, but I don’t have to either! Anyone can easily check for one just by using `@code_llvm`. To confirm an actual jump table is being generated (which, again, I could get neither the Julia compiler or GFortran to do), simply use `@code_native` and check for this [this kind of pattern](https://github.com/JuliaLang/julia/issues/10320#issuecomment-317493686).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 19, 2021, 10:58am UTC](https://discourse.julialang.org/t/is-there-a-select-case-equivalent-in-julia/66516/23 "2021-08-19T10:58:58Z")

</div>

I am fine with chained ternaries, was just suggesting another option.

Generally, a C-like `switch` is a very special case of control flow that can be handled with generic constructs, and not offering specialized syntax may be the right call. There are multiple solutions, so it is up to personal preference to pick one.

[Previous page](https://discourse.julialang.org/t/is-there-a-select-case-equivalent-in-julia/66516.md?page=1)
