The unless keyword semantics

This Elixir programming language really resonated with me, so I decided to get to know it a little bit further. I am going through the set of documentation provided in the learning guides.

Today I hit this section: case, cond, and if - The Elixir programming language

I was thinking the unless keyword will evaluate the following as true.

x = 7
unless x >= 7 do
  "Shoulda?"
end

But nothing got printed, is it the case that unless needs to totally negate a condition (x > 7 [In the aforementioned case]) in order for the body to be evaluated?

Thanks.

unless is a negation indeed.

unless x >= 7 is identical to if not(x >= 7) which we can simplify to if x < 7.

3 Likes

Thanks buddy!