From: Todd Benson Date: 2008-02-21T06:02:51+09:00 Subject: Re: displaying user inputed arrays On Wed, Feb 20, 2008 at 1:30 PM, Todd Benson wrote: > On Feb 17, 2008 9:18 AM, Isaac Toothyxdip wrote: > > > > [code] > > > > puts "Ok now enter in 5 words, just be sure there are spaces inbetween > > them" > > > > i = 0 > > while i < 5 > > words_group = gets["","","","",""] > > print "#{words_group[i]}" > > i =+ 1 > > end > > > > [/code] > > > > What im trying to do is ask the user to input some words and display > > them using arrays (learning program) i know you could do this easy other > > ways but im trying to do it with arrays. What needs to be changed? > > > > THanks in advance > > > > It depends if you _must_ have 5 words entered or if you just want the > first 5 words. In either case, look at the many available methods > split, compact, scan. Also... > > ((gets.scan /w'*/) - [""])[0..4] Wrong regexp anyways. That should have been more like... array = (gets.scan /[\w'-]*/) - [""] if array.length == 5 #do something else #do something else #for just printing it out #puts array or puts array.join(' ') end I think you get the general idea, though. The #scan method is doing the iterating for you (no need for while loop). Todd