OneBite.Dev - Coding blog in a bite size

use if conditional statement in Ruby

Code snippet on how to use if conditional statement in Ruby

a = 20

if a > 10
  puts "a is greater than 10"
else
  puts "a is less than 10"
end

The code above uses an if-else statement to compare the value of the variable “a” to the integer 10. First, the variable “a” is initialized with the value 20. Then, the if-else statement begins by checking if “a” is greater than 10. If it is, a message is output that reads “a is greater than 10”, otherwise the statement will run the code under the else condition, which outputs “a is less than 10”. This code can be used to test for conditions and take a different set of instructions based on the result.

ruby