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
Get step-by-step solutions from verified subject matter experts
