I need help with if statements

i am having trouble with if statements.
i want the program to check if the answer is yes or no then do the
process related to the answer but i cannot do it

any help ?

On Sat, Jan 29, 2011 at 8:38 PM, Dan L. [email protected]
wrote:

i am having trouble with if statements.
i want the program to check if the answer is yes or no then do the
process related to the answer but i cannot do it

any help ?


Posted via http://www.ruby-forum.com/.

if answer == ‘yes’

yes processing code

elsif answer == ‘no’

no processing code

else

what to do when answer is neither yes nor no

end

thanks :slight_smile:

On Sun, Jan 30, 2011 at 5:57 AM, Dan L. [email protected]
wrote:

thanks :slight_smile:

Here’s an alternative way using case statement that I personally find
nicer:

case answer
when “yes”

yes processing code

when “no”

no processing code

else
$stderr.puts “Wrong answer: #{answer}”
end

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs