Julia - trying to compare two strings

Viewed 117

I am trying to compare two strings I got as input, but it printed at me an error like "syntax: unexpected "="".

x = readline()
y = readline()

y = println(cmp(y, "Ciao"))
x = println(cmp(x, "Ciao"))


    
if  x=1
    println("Ho fatto un confronto in modo giusto")

elseif x=0
    println("No simone, non hai inserito quello che mi aspettavo")

elseif y=1
    println("Hai inserito la y e l'ho controllata, il programma funziona")

elseif y=0
    println("No simone, non hai inserito quello che mi aspettavo")

else println("Il programma non ha funzionato")
   
end 

return x,y
1 Answers

In Julia, you should use == for comparison: https://docs.julialang.org/en/v1/manual/mathematical-operations/#Numeric-Comparisons

This is different from assignment operator =, so for example

# Assignment
julia> x = 1
1

# Comparison
julia> x == 1
true

Also: println returns nothing so this code still wouldn’t work even with that fix. If you delete the calls to println and fix the assignments to be equality checks, then the code might work.

Related