i need help with if statements

D

Dan L.

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

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

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 ?
if answer == 'yes'
# yes processing code
elsif answer == 'no'
# no processing code
else
# what to do when answer is neither yes nor no
end
 
R

Robert Klemme


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,337
Messages
2,571,769
Members
48,561
Latest member
WileyBrant

Latest Threads

Top