How to write if else statements in Ruby?
In Ruby, if-else statements are straightforward and follow a clean syntax. Here is how we can write them:
Syntax:
if condition
# Code to execute if the condition is true
else
# Code to execute if the condition is false
end
Example:
age = 18
if age >= 18
puts "You are an adult."
else
puts "You are not an adult."
end