Skip to content

Instantly share code, notes, and snippets.

@tensiondriven
Created March 27, 2013 00:16
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 tensiondriven/5250517 to your computer and use it in GitHub Desktop.
Save tensiondriven/5250517 to your computer and use it in GitHub Desktop.
name.rb
def display_to_hundred
# range:
# print (1..100).to_a
# n = 0
# 100.times do
# n += 1
# puts n
# end
n = 0
while n < 100
n += 1
puts n
end
end
def display_multiples_of_seven(upto)
# n = 0
# upto.times do
# n += 1
# if n % 7 == 0
# print n
# end
# end
# n = 0
# while n < upto
# n += 1
# if n % 7 == 0
# #print "#{n}\n"
# puts n
# end
# end
(1..200).select{|n| n % 7 == 0}
# n = 1
# while n < upto
# puts n
# n += 7
# end
# n = 0
# while (n * 7) < upto
# puts n * 7
# n += 1
# end
(200/7).times{|n| puts (n + 1) * 7}
end
while true
puts "Please type A or B"
puts "A - Display 1 to 100"
puts "B - Display multiples of 7"
# Get the user's choice
choice = gets.chomp
# Run the method for the users choice
case choice.upcase
when 'A'
puts "OK, I'll Display 1 to 100"
display_to_hundred
when 'B'
puts "OK, I'll Display multples of 7 up to 200"
display_multiples_of_seven(200)
else
puts "I Dont know how to '#{choice}'!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment