# Error in setting a for loop

**URL:** https://discourse.julialang.org/t/error-in-setting-a-for-loop/50891
**Category:** New to Julia
**Tags:** question
**Created:** [November 28, 2020, 7:34am UTC](https://discourse.julialang.org/t/error-in-setting-a-for-loop/50891 "2020-11-28T07:34:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [November 28, 2020, 7:34am UTC](https://discourse.julialang.org/t/error-in-setting-a-for-loop/50891/1 "2020-11-28T07:34:31Z")

</div>

Hello,  
I am setting a for loop but I am getting an error:

```julia
epsilon = 1          
omega = 0.05      
tau = 2.392731385751533
mu = 0.72 
p = [epsilon, omega, tau, mu] 
for x in [0.0:0.1:1.0e9]
     println(x)
     y = ε * exp( ω * (ϑ-x) + (ω/μ) * (exp( -μ * (ϑ-x) ) - 1) )
     println(y)
end
0.0:0.1:1.0e9
ERROR: MethodError: no method matching -(::Float64, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}})
For element-wise subtraction, use broadcasting with dot syntax: scalar .- array
Closest candidates are:
  -(::ChainRulesCore.DoesNotExist, ::Any) at /home/gigiux/.julia/packages/ChainRulesCore/UayCG/src/differential_arithmetic.jl:25
  -(::Float64, ::Float64) at float.jl:403
  -(::Float64) at float.jl:393
  ...
Stacktrace:
 [1] top-level scope at ./none:3

```

Why is x not given as 0.0?  
What is the error about?  
It looks is a type of varibale error, so I checked the kind of x is generated during the executin:

```julia
for x in [0.0:0.1:1.0e9]
               println(typeof(x))
               y = ε * exp( ω * (ϑ-x) + (ω/μ) * (exp( -μ * (ϑ-x) ) - 1) )
               push!(Y, x)
           end
StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}
ERROR: MethodError: no method matching -(::Float64, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}})
For element-wise subtraction, use broadcasting with dot syntax: scalar .- array
Closest candidates are:
  -(::ChainRulesCore.DoesNotExist, ::Any) at /home/gigiux/.julia/packages/ChainRulesCore/UayCG/src/differential_arithmetic.jl:25
  -(::Float64, ::Float64) at float.jl:403
  -(::Float64) at float.jl:393
  ...
Stacktrace:
 [1] top-level scope at ./none:3

```

It looks like x is not extracted from the generator and also has a type different from the variables, since it should be of type Float64 (or even less since I don’t need so much precision after all).

I also tried to define the iterator with `linspace` but

```julia
?linspace
search: LinSolveGPUFactorize

Couldn't find linspace
Perhaps you meant isspace or isinplace
  No documentation found.

  Binding linspace does not exist.

```

Is there a new version of it?  
Thank you

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [November 28, 2020, 7:41am UTC](https://discourse.julialang.org/t/error-in-setting-a-for-loop/50891/2 "2020-11-28T07:41:14Z")

</div>

> [@Luigi\_Marongiu](#):
>
> `for x in [0.0:0.1:1.0e9]`

This is looping on an array that contains a range. You want to loop on the range itself: `for x in 0.0:0.1:1.0e9`.

---

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [November 28, 2020, 7:42am UTC](https://discourse.julialang.org/t/error-in-setting-a-for-loop/50891/3 "2020-11-28T07:42:22Z")

</div>

I see, it works! Thank you!

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 28, 2020, 1:58pm UTC](https://discourse.julialang.org/t/error-in-setting-a-for-loop/50891/4 "2020-11-28T13:58:33Z")

</div>

> [@Luigi\_Marongiu](#):
>
> I also tried to define the iterator with `linspace` but `Binding linspace does not exist.` Is there a new version of it?

Yes, it is nowadays called `range(start, stop, length=n)`.
