Skip to content

Instantly share code, notes, and snippets.

@geopet
Created September 25, 2012 06:05
Show Gist options
  • Save geopet/3780236 to your computer and use it in GitHub Desktop.
Save geopet/3780236 to your computer and use it in GitHub Desktop.
A better ruby fizzbuzz
100.times do |i|
if i % 5 === 0 and i % 3 === 0
puts 'fizzbuzz'
elsif i % 5 === 0
puts 'fizz'
elsif i % 3 === 0
puts 'buzz'
else
puts i
end
end
@geopet
Copy link
Author

geopet commented Sep 25, 2012

If you want to make sure it is 1-100, use 1.upto(100) do |i| instead of 100.times do |i|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment