Why 'else + condition' does not work but is not returning an error

Hi,

Is there a reason I didn’t get en error when I put a condition after an else ? (which is not taken into account)

a = true
b = false

if a
   @info "1"
else b
   @info "2"
end

Thanks

Because else is reserved for “all other conditionals are false”. You want elseif: Control Flow · The Julia Language

I know but it feels to me that we should get an error when adding a condition after a else ?

Oh, I see. The reason is because what you wrote is

a = true
b = false

if a
   @info "1"
else 
    b
   @info "2"
end

The new line after else is optional.

1 Like

Ah thanks :slight_smile: