if loop ruby code example
Example 1: 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 2: ruby if statement
if condition
expression
Example 3: ruby shorthand if
today == ChristmasEve ? (puts "Santa's On His Way!") : (puts "Snow")
Example 4: if else ruby
if condition
expression
else
expression