use exculsive ranges in case statements : case « Statement « Ruby






use exculsive ranges in case statements


temperature = 76
case temperature
when 0...65
  puts "Too cold!"
when 85...120
  puts "Too hot!"
when 65...85
  puts "Picnic time!"
else
  puts "Temperature out of reasonable range!"
end

 








Related examples in the same category

1.Here's the general format of the Ruby case statement:
2.Using the case Statement
3.If vs Case
4.case...when with range
5.use a case statement to make an assignment, which omits the value to test
6.elsif and case
7.All Ruby expressions return a result
8.Case with regular expression