Repeating Something and number even?

wang xiao bo 's photo
wang xiao bo
·Sep 2, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

To repeat something, Ruby provides us with times. We can use the do end block with it as shown below:

10.times do 
   puts "I love ruby"
end

Ruby provides .even? method to check if a number is even, .odd? method to check if a number is odd.

puts 2.even? // true
puts 21.even? //false
puts 2.odd?  // false
puts 21.odd?  //true
 
Share this