case statements keep your code cleaner when you're comparing one value against many possible options. They're great for handling things like grades, menu choices, user roles, or status codes.
ruby
grade = "B"
case grade
when "A"
puts "Excellent!"
when "B"
puts "Good job!"
when "C"
puts "Keep practicing."
else
puts "Invalid grade."
endcase grade takes the grade value and checks it against each when in turn. If nothing matches, else runs instead.
You should see
Good job!Info
When you have too many options, case is easier to read than a long chain of if elsif statements.