# \`in\` vs \`=\` in loop expressions

**URL:** https://discourse.julialang.org/t/in-vs-in-loop-expressions/110569
**Category:** Internals & Design
**Created:** [February 22, 2024, 10:10am UTC](https://discourse.julialang.org/t/in-vs-in-loop-expressions/110569 "2024-02-22T10:10:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [February 22, 2024, 10:10am UTC](https://discourse.julialang.org/t/in-vs-in-loop-expressions/110569/1 "2024-02-22T10:10:53Z")

</div>

Continuing the discussion from [Supporting syntax `x not in y` as alias for `!(x in y)`](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/7):

> [@Supporting syntax \`x not in y\` as alias for \`!(x in y)\`](https://discourse.julialang.org/t/supporting-syntax-x-not-in-y-as-alias-for-x-in-y/110146/6):
>
> I don’t view `in` as syntactic sugar for `=`, but rather `=` as a horrible alternative syntax for `in` that is there to appease people coming from certain programming languages – it is IMHO utterly confusing for anyone else

While I agree, I will note that the parser disagrees with you, and literally does treat `in` as syntactic sugar for `=` in loop expressions:

```julia-repl
julia> Meta.@dump (x for x ∈ y)
Expr
  head: Symbol generator
  args: Array{Any}((2,))
    1: Symbol x
    2: Expr
      head: Symbol =
      args: Array{Any}((2,))
        1: Symbol x
        2: Symbol y

```

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [February 22, 2024, 11:51am UTC](https://discourse.julialang.org/t/in-vs-in-loop-expressions/110569/2 "2024-02-22T11:51:06Z")

</div>

I can’t speak to the intentions of this design decisions, but I must say that I very much agree with it:

It is important that all three “spellings” normalize to the same AST pre-lowering, because macros need to understand `for` loops. It would deeply suck if macros needed to test against all valid spellings.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [February 22, 2024, 11:51am UTC](https://discourse.julialang.org/t/in-vs-in-loop-expressions/110569/3 "2024-02-22T11:51:45Z")

</div>

Sure, but they didn’t need to normalize to `=`. They could have normalized to `in` instead.

---

<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: [February 25, 2024, 2:34am UTC](https://discourse.julialang.org/t/in-vs-in-loop-expressions/110569/4 "2024-02-25T02:34:22Z")

</div>

`for =` long predated `for in`
