# "i in 3" is valid and continues to cost me some debug time :(

**URL:** <https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910>\
**Category:** General Usage\
**Tags:** ide\
**Created:** [January 6, 2026, 2:34pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910 "2026-01-06T14:34:48Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2026, 2:34pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/1 "2026-01-06T14:34:48Z")

</div>

Hi,

I spent a few hours to fix a bug where I was using an integer in place of a range

```julia-auto
for i in N
    do_something_with_i(i)
end

```

instead of

```julia-auto
for i in 1:N
    do_something_with_i(i)
end

```

I wish `i in 3` wasn’t a valid expression, but it is…  
Maybe some iDE hint could save me some time ? VSCode extension , other ?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [January 6, 2026, 2:40pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/2 "2026-01-06T14:40:29Z")

</div>

VS Code should already warn you in that case:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/0/70a3f7ad423cb87ea38d69e1e05bd138944adbbd.png)

It’s obviously quite basic, but at least addresses the literal case. Shouldn’t be too hard to support the case mentioned here too, probably.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2026, 2:59pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/3 "2026-01-06T14:59:06Z")

</div>

I do not get any warning for this function:

```julia-auto
function toto(N::Int)
    for i ∈ N
        println("i=$i")
    end
end

```

Maybe, I forgot to activate specific options in vscode ?  
Edit : You already said that it only catches the litteral case. Thanks.  
The non litteral case would be useful 🙂

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [January 6, 2026, 3:00pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/4 "2026-01-06T15:00:36Z")

</div>

Yeah, this only works for literal values in the loop iterator. So `i in 1` will show the warning, but `i in N` won’t even if we could know that `N` is an `Int`. That case is much harder to do reliably, although your case should be ok.

---

<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:** [January 6, 2026, 4:05pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/5 "2026-01-06T16:05:09Z")

</div>

This is why my preferred style (which I seem to be alone in, but _c’est la vie_) is to always use `for i = 1:n` when the inferrable is a literal range object and always use `for x in itr` when the intervals is anything besides a literal range. This uses the syntactic choice between `=` and `in` as an extra bit communicating user intent. If you accidentally write `for i = n` you could get a warning that you should either change it to `for i = 1:n` if you wanted to iterate a range or `for i in n` if you wanted to iterate `n` as a collection.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [January 6, 2026, 4:28pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/6 "2026-01-06T16:28:56Z")

</div>

> <https://github.com/julia-vscode/StaticLint.jl/pull/406>
>
> \<img width="921" height="669" alt="image" src="https://github.com/user-attachmen…ts/assets/1268f622-f8f8-47df-a312-922ed5985585" /\>

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/1/21a6b8831ec23361a7e88c762088aee7e905546c.png)

Everything more sophisticated will need to go into JETLS 🙂

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2026, 5:24pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/7 "2026-01-06T17:24:51Z")

</div>

I am afraid I do not get your point 😅

```julia-auto
function titi(N::Int)
    for i = N
        println("i=$i")
    end
end

```

does not trigger any warning. And in the `for i =` case I cannot even wish that the `in` operator was undefined for scalar RHS.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2026, 5:27pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/8 "2026-01-06T17:27:25Z")

</div>

Super Cool !

Will these hints be in the next release ?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 6, 2026, 6:42pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/9 "2026-01-06T18:42:43Z")

</div>

I think Stefan’s point was

> [@StefanKarpinski](#):
>
> If you accidentally write `for i = n` you **could** get a warning

(emphasis added)

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [January 6, 2026, 9:37pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/10 "2026-01-06T21:37:08Z")

</div>

Naturally 🙂

---

<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:** [January 7, 2026, 12:33am UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/11 "2026-01-07T00:33:47Z")

</div>

Yes, it would be a linter warning, but I haven’t convinced anyone. But it’s simple enough to check for that you can even do it with a regex.

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [January 7, 2026, 8:44am UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/12 "2026-01-07T08:44:12Z")

</div>

If you would like to have a warning, you could do this:

```julia-auto
function Base.iterate(x::Integer)
    @warn "Iterating over an integer (value: $x) - did you mean to use a range like 1:$x?"
    # Actually, integers iterate once, yielding themselves
    return (x, nothing)
end

function Base.iterate(x::Integer, state)
    @warn "Iterating over an integer (value: $x) - did you mean to use a range like 1:$x?"
    return nothing # Original behavior: iterate once
end

```

So that is the orgiginal implementation of iterators for numbers and now it just throws a warning. That has the benefit over error that it doesnt break packages which use them.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 7, 2026, 9:01am UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/13 "2026-01-07T09:01:41Z")

</div>

Neat.  
“gentle” kind if type piracy ?

---

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [January 7, 2026, 11:55am UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/14 "2026-01-07T11:55:35Z")

</div>

This breaks parts of the REPL in Julia 1.12.3:

1. Input `randn(5) ` (or `sin(5) `, or `sin(5)` without the trailing space), don’t press Enter yet.
2. _On the same line_ input `.`. The result should be `randn(5) .`
3. The warning will appear.

```Julia
julia> randn(5) .┌ Warning: Iterating over an integer (value: 1) - did you mean to use a range like 1:1?
└ @ Main REPL[1]:2
┌ Warning: Iterating over an integer (value: 1) - did you mean to use a range like 1:1?
└ @ Main REPL[2]:2
julia> sin(5) .┌ Warning: Iterating over an integer (value: 1) - did you mean to use a range like 1:1?
└ @ Main REPL[1]:2
┌ Warning: Iterating over an integer (value: 1) - did you mean to use a range like 1:1?
└ @ Main REPL[2]:2

```

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [January 7, 2026, 12:09pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/15 "2026-01-07T12:09:55Z")

</div>

That does not seem to be the case for me, with the same julia version:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/6/86d1d8ecf661f8131de111ae5188644395cabbec.png)

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [January 7, 2026, 12:12pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/16 "2026-01-07T12:12:30Z")

</div>

Ahh I get what you mean.  
Something like this `randn(5).`? But what is the `.` supposed to do?

---

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [January 7, 2026, 12:12pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/17 "2026-01-07T12:12:34Z")

</div>

I meant “input `sin(5) .` in the same line”, see edit to my post.

I tried to trigger some weird behavior with matrix multiplication, but everything worked fine. Then I tried _elementwise_ multiplication and wanted to input `randn(5) .* randn(5)`, but got the warnings in the middle of writing `randn(5) .`.

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [January 7, 2026, 12:15pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/18 "2026-01-07T12:15:05Z")

</div>

Ahh I get what you mean.

Well I guess that is to be expected when you do this kind of type piracy 😆

You will get the warnings everywhere, also in other packages. Even the REPL I guess 🏴‍☠️ 🦜

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [February 17, 2026, 2:52pm UTC](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time/134910/19 "2026-02-17T14:52:44Z")

</div>

This is now released in version 1.185 of the extension.
