Conditions ruby

Estimated reading time: 1 minute

flow control

  • operators

<, >, <=, >=, ==, !=, &&, ||

if/else

puts "Put in a number"
a = gets.chomp.to_i

if a == 3
  puts "a is 3"
elsif a == 4
  puts "a is 4"
else
  puts "a is neither 3, nor 4"
end

case

case is basically switch case

a = 5

case a
when 5
  puts "a is 5"
when 6
  puts "a is 6"
else
  puts "a is neither 5, nor 6"
end

source

ruby