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 ?

···

--
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

···

On Sat, Jan 29, 2011 at 8:38 PM, Dan L. <danissoepiclike@gmail.com> 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/\.

thanks :slight_smile:

···

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

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

···

On Sun, Jan 30, 2011 at 5:57 AM, Dan L. <danissoepiclike@gmail.com> wrote:

thanks :slight_smile:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/