-1

I'm trying to make a simple iteration process in Julia (language that I just began to learn) and I'm having some troubles. I want to evaluate the expression x > 0 && x <= 3 for values ranging from 0 to 3 in order to see when condition is true. I've tried so many ways and I can't find something in documentation which could help me. This is the code I just made (I tried many other combinations) but it's still not working:

x = [0,1,2,3]

for i in x
    if x > 0 && x <= 3 == true
        println("true")
    else
        println("false")
    end

I'm getting this message error:

syntax: incomplete: "for" at In[29]:3 requires end

Stacktrace:
 [1] include_string(::String, ::String) at .\loading.jl:522

Any help will be much appreciated.

Alejandro Carrera
  • 513
  • 1
  • 4
  • 14

1 Answers1

4

You need to end the for loop as well, you only ended the if statement.

for i in x
    if i > 0 && i <= 3
        println("true")
    else
        println("false")
    end
end
rokkerboci
  • 1,167
  • 1
  • 7
  • 14
  • I'm still getting an error: MethodError: no method matching isless(::Int64, ::Array{Int64,1}) Closest candidates are: isless(::Real, ::AbstractFloat) at operators.jl:97 isless(::Real, ::Real) at operators.jl:266 Stacktrace: [1] <(::Int64, ::Array{Int64,1}) at .\operators.jl:194 [2] macro expansion at .\In[35]:2 [inlined] [3] anonymous at .\:? [4] include_string(::String, ::String) at .\loading.jl:522 :/ – Alejandro Carrera Jan 28 '18 at 23:10
  • @AlejandroCarrera Corrected it, you were checking the array not the loop variable – rokkerboci Jan 28 '18 at 23:19
  • You can use `0 < i <= 3` instead of `i > 0 && i <= 3`. – DNF Jan 31 '18 at 20:03
  • @DNF Actually I don't know the language, so ... :) But thank you. – rokkerboci Jan 31 '18 at 20:47