Skip to content

Instantly share code, notes, and snippets.

@sranso
Created November 15, 2013 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sranso/7479300 to your computer and use it in GitHub Desktop.
Save sranso/7479300 to your computer and use it in GitHub Desktop.
fizzbuzz.rb
# prints numbers 1-100
# when the number is divisible by 3, say fizz
# when the number is divisible by 5 say buzz
# when the number is divisible by 3 and 5 say fizzbuzz
101.times do |i|
next if i == 0
if i % 3 == 0 && i % 5 == 0
puts "fizzbuzz"
elsif i % 3 == 0
puts "fizz"
elsif i % 5 == 0
puts "buzz"
else
puts i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment