# ERROR: syntax: extra token "for" after end of expression

**URL:** https://discourse.julialang.org/t/error-syntax-extra-token-for-after-end-of-expression/27317
**Category:** General Usage
**Created:** [August 8, 2019, 4:52pm UTC](https://discourse.julialang.org/t/error-syntax-extra-token-for-after-end-of-expression/27317 "2019-08-08T16:52:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [August 8, 2019, 4:52pm UTC](https://discourse.julialang.org/t/error-syntax-extra-token-for-after-end-of-expression/27317/1 "2019-08-08T16:52:47Z")

</div>

Hi, the following is the code.

```julia
function f(a,b)
       return a+b
end

```

then,

`julia> f(i,i) for i=1:3`

I got an error message, saying that extra token “for” after end of expression.

On the other hand, `sum( f(i,i) for i = 1:3 )` works out well. Could anyone kindly drop a comment?

---

<div class="post-metadata">

### Author: ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)
#### Post date: [August 8, 2019, 8:32pm UTC](https://discourse.julialang.org/t/error-syntax-extra-token-for-after-end-of-expression/27317/2 "2019-08-08T20:32:41Z")

</div>

I think what you’re looking for is `(f(i, i) for i=1:3)`. These are known as [generators](https://docs.julialang.org/en/v1/manual/arrays/#Generator-Expressions-1), and they require parentheses when used directly inside of a code block.

Note that generators are lazy sequences of values; if you want to materialize a vector, you can replace the `()` with `[]`: `[f(i, i) for i=1:3]`.
