我想用下面的代码重写下面的代码,但我被卡住了。ruby程序基本设计说明
def ask question
good_answer = false
while (not good_answer)
puts question
reply = gets.chomp.downcase
if (reply == 'yes' or reply =='no')
good_answer = true
if reply == 'yes'
answer = true
else
answer = false
end
else
puts 'Please answer "yes" or "no"'
end
end
answer
end
替换代码:
def ask question
puts question
reply = gets.chomp
if (reply == 'yes' or reply == 'no')
puts reply.capitalize
else
puts 'Please enter "yes" or "no"'
#jump the code to like 2 (but how?)- use while reply != empty & comment the below lines
puts question
reply = gets.chomp
end
end
我要跳转到程序的主要部分是没有任何跳转,跳转或我可以调用方法,该方法里面?
Ruby通常是用两个空格缩进的,而不是四个。 – 2012-01-04 21:48:04