有没有办法在Ruby中通过单个命令退出两个循环?

Vij*_*jay 3 ruby loops

这是示例代码,

while true
   while true
      exit all loops when condition true
   end
end
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我,当第二个循环中断时,是否有可能退出第一个循环,但后来我只想使用一个break命令而不是加注.

Ser*_*sev 7

你知道什么比只使用一个更好break吗?完全不使用任何东西!:)

很少使用throw/catch这里很好

catch(:done) do 
  while cond1
    while cond2
      throw :done if condition
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请参阅文档throwcatch.