From: Rob Biedenharn Date: 2010-01-23T00:49:00+09:00 Subject: Re: Argh?! :) kEND, $end and kELSE in a simple program On Jan 22, 2010, at 10:33 AM, Jet Koten wrote: > Hi, > > I'm completely new to programming and am learning using Ruby. > > I'm trying to get this program working using only these basic commands > that are in my program: > > puts 'Say something to the virtual hard-of-hearing Grandpa:' > while true > said=gets.chomp > year = (1930+rand(51)) > counter=0 > if said=='GOODBYE' > counter+=1 > if counter==3 > break > end > end > elsif said !=said.upcase > puts 'HUH?! SAY IT LOUDER!' > counter-=1 > end > else > puts 'NO, NOT SINCE '+year.to_s+'!' > counter-=1 > end > end > > So basically it's supposed to be that it'll just loop forever unless > you > say GOODBYE three times in a row... and not just three times with > something else in between. > > Otherwise if you say anything lowcase it'll say HUH?! [...] and if you > say anything upcase it should say NOT SINCE and a random number > between > 1930 and 1950. I had all the basic functionality working like this: > > puts 'Say something to the virtual hard-of-hearing Grandpa:' > while true > said=gets.chomp > year = (1930+rand(21)) > if said !=said.upcase > puts 'HUH?! SAY IT LOUDER!' > else puts 'NO, NOT SINCE '+year.to_s+'!' > end > end > > > I'm really stuck about getting 'him' to break after the 3 GOODBYEs > in a > row, I've written the code the best I can and now all I get are > various > combinations of kEND, $end and kELSE. I'm guessing it's some kind of > scope issue but I don't know enough to know what I don't know... you > know? :) > > Can anyone see what will get 'him' working using just the same basic > commands that are in this program already? > > Thanks in advance. You have extra 'end's where you don't need them (see the ones I commented out): puts 'Say something to the virtual hard-of-hearing Grandpa:' while true said=gets.chomp year = (1930+rand(51)) counter=0 if said=='GOODBYE' counter+=1 if counter==3 break end #end elsif said !=said.upcase puts 'HUH?! SAY IT LOUDER!' counter-=1 #end else puts 'NO, NOT SINCE '+year.to_s+'!' counter-=1 end end In general, kEND or kELSE means that is a keyword either missing of found where it shouldn't be. And $end means the end of the file. So if you get an error like: "syntax error, unexpected $end, expecting kEND" It means: "you seem to have broken one of Ruby's syntax rules, I ran out of stuff in this file to look at while I was looking for an 'end' keyword" -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com