Unless? question


#1


Why should i write two equals ( ==) in unless ?!


#2

== is the comparison operator. = is for making assignments.

unless x == 0 { }

The code inside the block will only execute when x is not equal to zero.


#3

Thanks , that helped me a lot .


#4

That was pseudo code, though, so will throw an error, just so you know. We cannot actually write a block after unless.

x = 1
unless x == 0
    puts x
else
    puts "Oops!"
end

Sorry if I misled you.


#5

Ohh thank you , now i understand it but sorry can i ask one more question ? why did they want me to write " != " instead of " = "


#6

!= means not equal to, == means equal to. We only use a single = for making an assignment.

a = 1
a == 1    # true
a != 1    # false

#7

Thank you very much for your help .