On Dec 15, 11:48 pm, Daniel Peikes <danpei... / hotmail.com> wrote:
> Ok folks I know this is an easy question, I am trying to write a while
> loop with a logical or statement and am new to ruby.  The online guide I
> am using does not seem to cover and and or statements for some reason.
> My guess being a C programmer is to do it like this:
> while again != "y" || "n"
>
> I am looking for confirmation, also suggestions of a better online guide
> to learn Ruby preffrubly with project to do that include instructions.
> Thanks in advance.
> --
> Posted viahttp://www.ruby-forum.com/.

Also, again != "y" || "n" evaluates to ((again != "y") == true) ||
("n" == true)...

puts "oops" if ("b" != "b" || "a")
# => oops

...the "b" != "b" branch is false, but then we just get a string on
the other branch (rather than the condition "b" != "a"), and since "a"
is not nil/false is evaluates as true (though you'll get a warning
about using a string literal as a condition). If you want to test a
condition on different branches, you have to specify the testee on
each one...

again == "y" || again == "n" || again == "maybe"

...or use a short-cut...

["y", "n", "maybe"].include?(again)

Regards,
Jordan