Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: Joel VanderWerf Newsgroups: comp.lang.ruby Subject: Re: Help with while condition OR condition Date: Sat, 7 May 2011 17:56:47 -0500 Organization: Service de news de lacave.net Lines: 55 Message-ID: <4DC5CE2A.9070402@gmail.com> References: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1304809064 23440 65.111.164.187 (7 May 2011 22:57:44 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Sat, 7 May 2011 22:57:44 +0000 (UTC) In-Reply-To: X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 382793 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <4DC5CE2A.9070402@gmail.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:4083 On 05/07/2011 03:37 PM, Bill W. wrote: > Hi everyone, > > This is my first post, so I hope I don't sound too inexperienced.. > > I'm trying to teach myself Ruby, and have run into an issue with a while > statement that will break if an input is "exit" or "quit". > As of right now, it works if exit is input, but not quit > > I know I am completely misusing the entire thing, but here is what I > came up with: > > EXIT = "exit" #need constants since Ruby gets pissed at string literals > QUIT = "quit" #in a comparison > > print "Input: " > input = gets > while input.chomp.downcase != (EXIT || QUIT) #only works for exit It can help to take apart expressions in irb (interactive ruby): $ irb >> EXIT = "exit" => "exit" >> QUIT = "quit" => "quit" >> EXIT || QUIT => "exit" >> "quit" == (EXIT || QUIT) => false > #Do something > > print "Input: " #pick up the next input and check it > input = gets > end > > I know that Ruby has a lot of shortcuts, but if you post any please > explain how they work (or provide a link to a good explanation. Something to tinker with: print "Input: " while input = gets case s = input.chomp.downcase when "exit", "quit" puts "You wanted to #{s} this mighty fine program?" break else puts "Why do you say '#{s}'?" print "Input: " end end puts "Done."