This if statements is not work properly

julia> function step_function(x)
           if x > 0
               return 1
           eles
               return 0
           end
       end
step_function (generic function with 1 method)

julia> x = [-1.0, 1.0, 2.0]
3-element Array{Float64,1}:
 -1.0
  1.0
  2.0

julia> [step_function(i) for i in x]
3-element Array{Union{Nothing, Int64},1}:
  nothing
 1       
 1       

I think this is wrong output. is Right output that:

3-element Array{Int64,1}:
 0
 1
 1

Why first output is nothing? this is my question.

You’ve got a typo there - I think it should be else, not eles. As you’ve written it, everything between if and end is part of the if block. Since the branch in there isn’t taken, the last value will be returned by default, which in this case is nothing.

3 Likes

OHH!! think you!! my elementary mistake!