The else statement can be used in conjunction with the if and unless statements.
The else statement will be executed if the if branch or the unless branch is not executed.
value = 1
if value == 1
"1 is equal to 1"
else
"1 is not equal to 1"
end
# => "1 is equal to 1"
unless value < 2
"1 is not greater than 2"
end
# => "1 is greater than 2"
--
Change to below , because unless is executed when condition is falsey
unless value < 2
"1 is not greater than 2"
end
# => nil
Else statement
The
else
statement can be used in conjunction with theif
andunless
statements. Theelse
statement will be executed if theif
branch or theunless
branch is not executed.-- Change to below , because unless is executed when condition is falsey