0
如果此代碼執行else
語句,我希望它可以從rescue
或begin
重試。 運行代碼向我詢問輸入信息,當我輸入代碼時,代碼不起作用。開始救援重試錯誤
1-我能做些什麼來使這個代碼與運行retry
的else語句一起工作?
2-爲什麼刪除rescue
創建retry Syntax Error
?
# Creates input method
def input
x = gets.to_i
end
#Begins the first choice
begin
puts "What will you do?
1- Get a closer look
2- Go in the opposite direction
Write your input an press enter:"
rescue
#Calls input method
choice = input
if choice == 1
puts "You get a closer look and..."
elsif choice == 2
puts "You go in the opposite direction, out of trouble"
else
puts "Incorrect input, enter a number between the one's avaliables:"
end
#Retries if the choice is error
retry if choice != 1||2
end
謝謝,那正是我一直在尋找的。 :) –