环路我只想做一个简单的循环:麻烦与红宝石
我想是这样的:
loop do
puts "What hotel would you like to pick"
hotelCode = gets.chomp.downcase #gets user input and puts it lowerCase
if hotelCode != "a" || hotelCode != "b" || hotelCode != "c" || hotelCode != "d" # if user input is not a,b,c,d break
break
else
puts "How many nights would you like to stay"
nights = gets.chomp.to_i
end
end #end while loop
puts "congrats u got out"
在我的代码,它只是不断打破循环,无论我做什么。我错过了明显的东西吗?
您正在使用'||'。你想'&&'。如果它是“a”,那么它是!=“b”,所以条件仍然是正确的。 –
...让我再也不说这个了!\ – sublimeaces