ruby if else code example
Example 1: ruby unless
unless number.even?
# runs if `number` is NOT even
else
# runs if `number` is even
end
Example 2: ruby else if
x = 1
if x > 2
puts "x is greater than 2"
elsif x <= 2 and x!=0
puts "x is 1"
else
puts "I can't guess the number"
end
Example 3: ruby if statement
if condition
expression
Example 4: if else ruby
if condition
expression
else
expression
Example 5: ruby if else
if true
"if statement"
elsif false
"else if, optional"
else
"else, also optional"
end