The keyword “not” is different from the others. The “not” keyword gets an expression and inverts its boolean value – so given a true condition it will return false. It works like “!” operator in Ruby, the only difference between “and” keyword and “!” operator is “!” has the highest precedence of all operators, and “not” one of the lowest.
Syntax:
not expression
Example 1:
Ruby
uname = "geeks"
if not (uname == "Geeks" )
puts "Incorrect username!"
else
puts "Welcome, GeeksforGeeks!"
end
|
Output:
Incorrect username!
Example 2:
Ruby
uname = "Geek"
password = "Wel123"
number = 123
if not (uname == "Geek" &&
password == "Wel123" &&
number == 123 )
puts "Hey, Incorrect Credentials"
else
puts "Welcome to GeeksforGeeks"
end
|
Output:
Welcome to GeeksforGeeks
Last Updated :
27 Jul, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...