Programmer967
Programmer967

Reputation: 51

Julia - trying to compare two strings

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

Upvotes: 5

Views: 1066

Answers (1)

Andrej Oskin
Andrej Oskin

Reputation: 2342

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.

Upvotes: 7

Related Questions