How to use nested if statements in Ruby

1 Answer

0 votes
a = 200
s = "Ruby"

if a > 200
  if s == "Ruby"
    puts "a > 200 and s == \"Ruby\""
  else
    puts "a > 200 and s != \"Ruby\""
  end
else
  if s == "Ruby"
    puts "a <= 200 and s == \"Ruby\""
  else
    puts "a <= 200 and s != \"Ruby\""
  end
end



# run:
# 
# a <= 200 and s == "Ruby"
#

 



answered Dec 21, 2020 by avibootz
...