On Fri, Dec 9, 2011 at 19:14, Emeka Patrick <emekapatrick / gmail.com>
wrote (rearranged a bit for illustrative purposes):

> I got this program to work by rewriting it

[from]

> while true
>  puts question
>  reply = gets.chomp.downcase
>
>  if (reply != 'yes' || reply != 'no')
>   puts 'Please answer "yes" or "no".'
>  elsif reply == ''
>  break
>  end
> end

[to]

> 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

The trick is that || means "or".  The first time, you're saying "if
the reply isn't yes, or it isn't no, ask again, else if it's blank,
break".  No matter what the reply is, it's either going to be not yes,
or not no.  The second time, you're saying 'if it IS yes, or it IS no,
break, else ask again (and if it's blank, break)".  If you want to use
!=, what you need there is && (and) rather than || (or).

If it helps, you can actually use the words "and" and "or" instead of
the || and &&.  There are some situations in which there are
differences, but in this case it should be OK.

A general technique that might help is "pseudocoding".  Write out
first, what it would look like in plain English (or whatever your
native language is) if you were giving instructions to a person -- a
fairly simple-minded person who is excellent at following instructions
exactly as given (no matter how wrong they may be), very quickly.
Read that over, trying to "think" like such a person.  Maybe even
simulate it step by step by writing down the values of variables.
When that gives you the results you want, then start translating it
from English to Ruby.  That's how most people start out learning to
program.  When you get good at it, then you can skip the English step.

-Dave

-- 
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)