1
如果if语句转到'else',可以让重复if语句吗?如果转到'else',重复if语句
这是一个代码的一部分:
puts "While you are walking you find a small jar containing honey. Do
you take it? yes/not"
choice = $stdin.gets.chomp
if choice.include?("yes")
honey = true
puts " "
puts "You put the small honey jar in your bag and then keep walking."
elsif choice.include?("not")
puts "Ok! maybe you are right. Better leave it!"
puts "You keep going"
honey = false
else
" "
puts "Answer yes or not."
end
所以我想,如果用户不是或不是那种if语句再次运行,可能再次提出的问题或只是给了“其他'的信息,并再次给出写出答案的可能性。谢谢。
感谢的提示。但是,在这种情况下,我决定使用'while'而不是'loop do',因为在循环中我需要修改局部变量并在循环之后使用它。使用'while'这可能与'循环做'这不是。本地变量不会被修改。 –
@MarcoVanali:它仍然是一个循环:)你也可以看看埃里克的答案。很有用。 –