ruby ending methods other than end -


awords = [] word = "x"  puts "type many words want, or press \"enter\" quit." while word != ""enter code here   #get word user   word = gets.chomp   if word == ('')     puts 'you input nothing'   end    #add array   awords.push word  end    #user exited loop test array before printing  puts "now sorting typed.. thanks." puts awords.sort 

everything works fine, want program skip last 2 "puts" if users don't input anything. there anyway stop program after puts 'you input nothing' if users decide not input press enter?

if don't want puts last 2 lines, should check make sure there values within awords.

awords = [] word = 'x'  puts "type many words want, or press \"enter\" quit." until word.empty?   word = gets.chomp   if word.empty?     puts 'you input nothing'   end    awords << word end   # check make sure awords has values in unless awords.empty?   puts "now sorting typed.. thanks."   puts awords.sort end 

now easiest way stop program if no input ever given add line after puts 'you input nothing' return.

puts 'you input nothing' return if awords.empty? 

you'll notice changed lot of == '' methods .empty? because ruby way of doing type of check strings.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -