Question: How do you use a user inputted string as a conditional statement in Ruby? Below is an example of some code (again, in Ruby); when

How do you use a user inputted string as a conditional statement in Ruby? Below is an example of some code (again, in Ruby); when I try to run the code below the loop continues on endlessly and prints out 'choice = yes', no matter what is inputted. It is as if the code does not acknowledge the variable.

----------------------------------------------------------------------------------------------------------------

#declare and initialize variable $choice = ""

#prompt to enter loop while ($choice != "no") #the loop to have user enter letter

print ('Do you want to enter a letter (enter yes or no)? ') $stdout.flush() #method needed for SciTE to take in input $choice = gets()

if ($choice == "no") puts ('choice = no') end #end if else statement

puts ('choice = yes')

end #end while loop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!