I can't exit out of my "until" loop

exit=false

until exit==true do
puts “Libertyland Income Tax Calculator Program”

print “Legal Name:”
legal_name=gets.to_s

print “Enter total income:$”
gross_income=gets.to_f

if gross_income<=15000
puts “Your current annual income exempts you from paying income
taxes.”
else
tax_payer_profile=TaxCalculator.new(legal_name,gross_income)
puts tax_payer_profile
puts “Your tax bill in LibertyLand
is:$#{tax_payer_profile.tax_bill_under_new_regime}”
end

puts “Would you like to continue? yes or no”
print “Response:”
response=gets.to_s
final_response=response.downcase

if final_response==“no”
exit=true
end

end

Why won’t my program terminate when I type in “no” even though I have
set the variable exit equal to “true”, which is my conditional for the
until loop?

Try gets.chomp. And, to_s is useless cause gets return a string. Also,
in a boolean context, you don’t need something like until exit==true,
until exit is enough.

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