On 3/31/06, Jan_K <non / none.com> wrote: > On Sat, 1 Apr 2006 02:08:40 +0900, "Bill Guindon" <agorilla / gmail.com> > wrote: > > >On 3/29/06, Jan_K <non / none.com> wrote: > >[snip] > >> I can't use "Until" because it wasn't covered in the book so far (even > >> though it seems pretty straightforward what it does). Ditto for "+-" > >> > >> What was covered so far up until this chapter: > >> > >> if, else, elsif, while > >> > > > >Here's a very simplified example that I believe uses only what's been > >covered up to that point. > > > >last_input = '' > >goodbye = 1 > > > >while goodbye < 3 > > input = gets.chomp > > > > if input == input.upcase > > puts "NO, NOT SINCE " + (1930 + rand(21)).to_s > > else > > puts "HUH?! SPEAK UP, SONNY!" > > end > > > > if input == 'BYE' and last_input == 'BYE' > > goodbye = goodbye + 1 > > else > > goodbye = 1 > > end > > > > last_input = input > >end > > > I'm not really understanding what last_input is exactly doing. Looks > like nothing. I may be reading ahead of you, but it doesn't look like it. http://pine.fm/LearnToProgram/?Chapter=06 It's there to honor this spec: "Change your previous program so that you have to shout BYE three times in a row. Make sure to test your program: if you shout BYE three times, but not in a row, you should still be talking to grandma." It's making sure that it exits when you say: "BYE", "BYE", "BYE" but it won't exit if you say: "BYE", "DOG", "BYE", "BYE" If that's what you typed, on the third input, last_input would be "DOG", so 'goodbye' would get reset to '1'. > This works without any problems: > > > goodbye = 1 > > while goodbye < 4 > input = gets.chomp > > if input == input.upcase > puts "NO, NOT SINCE " + (1930 + rand(21)).to_s > else > puts "HUH?! SPEAK UP, SONNY!" > end > > if input == 'BYE' > goodbye = goodbye + 1 > else > goodbye = 1 > end > end > > -- Bill Guindon (aka aGorilla) The best answer to most questions is "it depends".