我正處於學習Ruby的早期階段,並在嘗試爲我的某個程序創建條件語句時遇到了問題。如果orignal不符合前兩個條件的條件,我基本上希望它回滾並獲得新的輸入值。在if/else語句中創建循環
因此,例如:
puts "Choose either the 'red' or 'blue' pill"
choice = gets.to_s.downcase.chomp
if choice == red
puts "Fasten your seatbelt dorothy 'cause kansas is going bye-bye"
elsif choice == "blue"
puts "The story ends, you wake up in your bed and believe whatever you want to believe"
else
puts "You have to choose one"
end
是'red'變量?如果不是,'choice == red'將會失敗。重要的是你的源代碼可以運行。 –