puts “Enter starting year:”
starting_year = gets.chomp.to_i
puts “Enter ending year:”
ending_year = gets.chomp.to_i
year = starting_year
while true
if year%4==0
if year%100!=0 || year%400 ==0
puts year.to_s + ’ is a Leap Year’
end
end
year = year +1
break if year >= ending_year
end
starting_year.upto(ending_year) do |year|
if year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
puts “#{year} is a leap year”
end
end
which saves 3 lines of code and some possibilities for typos/bugs.
BTW, for an infinite loop there exists `loop do … end’.
thanks for posting this solution, I like it better as it saves lines of
code, it looks clean. I am 58 and new to programming with ruby being my
first language. I also just got my ccna but there doesn’t seem to be any
work in networking, I didn’t understand other languages but I seem to be
getting ruby. this is great!!