使用用户输入中断 while 循环
Break while loop using user input
我怎样才能通过用户输入跳出循环 示例输入不是 yes 只会让我跳出循环
enter image description here
def main
loop do
# ...
puts "Repeat for another input?"
ans = gets.chomp
if ans != "yes"
break # will break the loop
end
end
end
main
我怎样才能通过用户输入跳出循环 示例输入不是 yes 只会让我跳出循环 enter image description here
def main
loop do
# ...
puts "Repeat for another input?"
ans = gets.chomp
if ans != "yes"
break # will break the loop
end
end
end
main