From: Matthew Smillie Date: 2006-06-27T03:42:11+09:00 Subject: Re: Stumped:beginners question On Jun 26, 2006, at 19:26, Dark Ambient wrote: > On 6/26/06, Rob Biedenharn wrote: >> OK, first I just *have* to ask: Do you have a copy of Programming >> Ruby? >> >> No? Get the first edition here: http://www.ruby-doc.org/docs/ >> ProgrammingRuby/ >> >> keep reading...! >> > This is the while explanation (most of it) from PR 2nd edition , > which I own. > > while boolean-expression [ do | : ] > body > end > executes body zero or more times as long as boolean-expression is > true. > until boolean-expression [ do | : ] > body > end > > It doesn't help me one bit (literally), not with correctly setting > up the loop. Your biggest problem in the code you put up is that you're using the same variable for several different things: a (apparently redundant) parameter to the method, a loop condition, and to hold user input - it's much better, especially when you're learning to program, to use separate variables for these separate concerns. There are several problems with the code, one of which is (again) the bad choice of loop condition, observe your code stripped down to only the bits which affect the loop continuing or not: sort = '' while sort == '' sort = gets.etc.etc # sort != '' end So, at the end of the loop, sort != '', and the loop terminates. The answer (again) is to pick a loop condition that you know will be true as long as you want the loop to continue. This is pretty accurately described in the excerpt you posted - for the first loop, the condition is true, so the body executes. For the next iteration, the condition is false, so the loop body doesn't execute, and the program continues. matthew smillie.