(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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -