In this program
def ask question
while true
puts question
reply = gets.chomp.downcase
if (reply != 'yes' || reply != 'no')
puts 'Please answer "yes" or "no".'
elsif reply == ''
break
end
end
end
puts 'Hello, and thank you for...'
puts
ask "Do you like eating tacos?" # Ignore this return value
ask "Do you like eating burritos?" # And this one
wets_bed = ask 'Do you wet the bed?' # Save this return value
ask 'Do you like eating chimichangas?'
ask 'Do you like eating sopapillas?'
puts 'Just a few more questions...'
ask 'Do you like drinking horchata?'
ask 'Do you like eating flautas?'
puts
puts 'DEBRIEFING:'
puts 'Thank you for...'
puts
puts wets_bed
am I stuck in a loop where no matter whether I enter 'yes' or 'no' or
anything at all after I'm asked
···
---
Hello, and thank you for...
Do you like eating tacos?
---
I get back
---
Please answer "yes" or "no".
Do you like eating tacos?
---
because I decided to ask if reply is different than 'yes' and/or
different than 'no'? as well as ask if it's the same as an empty string,
basically saying that this is a situation that will always be true?
I got this program to work by rewriting it
def ask question
while true
puts question
reply = gets.chomp.downcase
if (reply == 'yes' || reply == 'no')
break
else
puts 'Please answer "yes" or "no".'
if reply == ''
break
end
end
etc etc....
, but I want to understand what I'd need to do to get it to work with !=
method.
Any insight / help would be appreciated.
Thanks,
Emeka
PS
I know since I didn't save a value for wets_bed I'm going to get nil
back, but just want to figure out the other stuff first.
---------
--
Posted via http://www.ruby-forum.com/.