use a conditional to check greater than number in Ruby
Code snippet on how to use a conditional to check greater than number in Ruby
num1 = 7
num2 = 5
if num1 > num2
puts "num1 is greater than num2"
end
This code checks if the value of the first variable (num1) is greater than the second variable (num2). First, two variables (num1 and num2) are declared and each assigned a numerical value (7 and 5, respectively).
Then, the code uses an if statement to check if the value of num1 is greater than the value of num2. If the condition is true, a message is printed that says “num1 is greater than num2”. If the condition is false, nothing is printed. In this case, because num1 is greater than num2, the message is printed.