(Ruby) Counting in Loops -
could me out, please?
i want write ruby code in such way when word "bye!" 3 times in row, terminates program.
my code below
quotes = file.readlines('quotes.db') puts = "what?" print ">" request = gets.chomp while request != "bye!" puts quotes[rand(quotes.length)] puts ">" request = gets.chomp end
any amend code follow rules want?
puts 'if type bye 3 times, program terminate' bye_counter = 0 loop input = gets.chomp if input == 'bye' bye_counter += 1 else bye_counter = 0 end break if bye_counter == 3 end
Comments
Post a Comment