From: John W Higgins Date: 2011-12-10T07:05:53+09:00 Subject: Re: Learn To Program (Chris Pine) - Building and Sorting Array --bcaec51b1ea7e43f5804b3affca8 Content-Type: text/plain; charset=ISO-8859-1 Good Day Emeka, On Fri, Dec 9, 2011 at 12:47 PM, Emeka Patrick wrote: > Hi Robert, > > Thanks so much for getting back to me on this much appreciated. Some > questions in-line below. > Thank you for at least attempting to figure things out. Very refreshing in contrast to some of the questions that people pose here........ > > Robert Klemme wrote in post #1035877: > > On Fri, Dec 9, 2011 at 9:58 AM, Emeka Patrick > > wrote: > >> Super new to programming (1 week or so) and working through 'Learn to > >> Program' to get an understanding of Ruby before moving on to trying my > >> hand at Ruby on Rails. That being said I was having a bit of trouble > >> working through the first "A Few Things To Try" in section 8.3. > > > > Welcome to the world of Ruby! > > > >> '. Basically, I don't think I get what I'm making response equal to, is > >> it an empty string, or? > > > > != and == are tests and not assignments. If you exchange == for != > > you also need to exchange branches of the if else end construct. > > So basically with != and == I'm asking if what precedes the expression > is either "different from" or "the same as" whatever follows. Am I > correct? > That would be correct. > Also, I still don't think I fully understand the empty string. In the > two lines of code... > > if response != '' > responses.push response > > ...am I doing something like "Is what was entered for the variable > response different from an empty string? If so then push whatever string > is entered to the end of the responses array." > That would also be correct. One other small item, normally code is indented (Ruby standard is 2 spaces) another level inside a control statement (if/while/else and such) to make it slightly easier to read the code. Taking your earlier work if response != '' responses.push response else puts responses.sort break end It seemed to me that the logical way to enter this code would be > > responses = [] > response = gets.chomp > > while response != '' > responses.push response > end > > puts responses.sort > Actually very close here. Your problem is that you end up in an endless loop because you never get another entry from the user. This should do the trick responses = [] response = gets.chomp while response != '' responses.push response response = gets.chomp # get another line from the user end puts responses.sort But very very close for someone just picking up programming. You appear to at least grasp the basic mechanics of working through a problem! Best of luck to you! John --bcaec51b1ea7e43f5804b3affca8--