環路我只想做一個簡單的循環:麻煩與紅寶石
我想是這樣的:
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