# Why doesn't Julia have the \`switch-case\` structure?

**URL:** <https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936>\
**Category:** General Usage\
**Tags:** question, syntax\
**Created:** [February 29, 2024, 8:24am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936 "2024-02-29T08:24:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [February 29, 2024, 8:24am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936/1 "2024-02-29T08:24:22Z")

</div>

Why doesn’t Julia have the `switch-case` structure? Is it unnecessary, or is there a better solution?

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 29, 2024, 8:32am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936/2 "2024-02-29T08:32:20Z")

</div>

I suggest [Pattern Matching — MLStyle.jl Documentation](https://thautwarm.github.io/MLStyle.jl/latest/syntax/pattern.html)

```julia
julia> @match 10 begin
           1 => "wrong!"
           2 => "wrong!"
           10 => "right!"
       end
"right!"

```

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [February 29, 2024, 8:35am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936/3 "2024-02-29T08:35:43Z")

</div>

Thank you for introducing me to a very attractive package. 🤝 🤝

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 29, 2024, 8:59am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936/4 "2024-02-29T08:59:40Z")

</div>

If you’re curious, there’s a lively discussion here: [A case/switch statement for Julia · Issue #18285 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/18285). TLDR it could be a macro instead of being incorporated into the base syntax, as if-statements can already undergo the optimizations switch statements do. Packages have already made such macros, Match.jl is actually referenced in that issue.

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [February 29, 2024, 9:26am UTC](https://discourse.julialang.org/t/why-doesnt-julia-have-the-switch-case-structure/110936/5 "2024-02-29T09:26:58Z")

</div>

Thanks for guidance! 🤝
