# Extra token, on same line as for loop start, is valid?

**URL:** <https://discourse.julialang.org/t/extra-token-on-same-line-as-for-loop-start-is-valid/20185>\
**Category:** Internals & Design\
**Created:** [January 28, 2019, 3:46pm UTC](https://discourse.julialang.org/t/extra-token-on-same-line-as-for-loop-start-is-valid/20185 "2019-01-28T15:46:29Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 5, 2019, 8:26pm UTC](https://discourse.julialang.org/t/extra-token-on-same-line-as-for-loop-start-is-valid/20185/8 "2019-02-05T20:26:05Z")

</div>

Perhaps it would have made sense to require semicolons. I don’t know why it was done this way, there’s probably a good reason. Several other keywords work this way too, such as `if` and `while`. However, `let` requires a semicolon:

```julia
julia> let a = 3 println(a) end
ERROR: syntax: let variables should end in ";" or newline

```

What’s more surprising to me is that not even a space is required before an `end` statement. This is perfectly valid:

```julia
julia> a = 3; while a > 0 println(a); global a-=1end
3
2
1

```

As for linter and warnings, looking again at the code that troubled you: `for i in 1:3 4`, it might be more effective to detect and warn about that independent `4`, than requiring semicolons after keywords. (Or are there cases where a single number like that would make sense, unless when used as a return value?)

What I think can be said with certainty is that changing this would break an enormous amount of code, and would likely have to be done over a series of releases (like v0.7 and v1.0). I have used this syntax many times, especially when answering questions on this forum to keep my replies more compact – [here’s an example:](https://discourse.julialang.org/t/simple-loop-wont-vectorize/20169/7)

> ```julia
> @btime (s = 0.0; @simd for i in 1:10^9 s += i * 1.23 end; s)
> 
> ```

There’s also plenty of existing code out there using this syntax, [here’s an example in Julia’s sparse matrix library:](https://github.com/JuliaLang/julia/blob/master/stdlib/SparseArrays/src/sparsematrix.jl#L1476)

> ```julia
> for i in (k + 2):(n + 1) colptr[i] = (k + 1) end
> 
> ```

---

_[View the full topic](https://discourse.julialang.org/t/extra-token-on-same-line-as-for-loop-start-is-valid/20185)._
