gpt4 book ai didi

ruby - 有没有一种方法可以通过 Ruby 中的单个命令退出两个循环?

转载 作者:数据小太阳 更新时间:2023-10-29 07:46:12 25 4
gpt4 key购买 nike

这是示例代码,

while true
while true
exit all loops when condition true
end
end

有人能告诉我是否可以在第二个循环中断时退出第一个循环,但我只想使用一个 break 命令而不使用 raise。

最佳答案

你知道什么比只使用一个break更好吗?一点都不用! :)

很少使用的throw/catch在这里很好

catch(:done) do 
while cond1
while cond2
throw :done if condition
end
end
end

有关更多信息,请参阅 throw 上的文档和 catch .

关于ruby - 有没有一种方法可以通过 Ruby 中的单个命令退出两个循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29797566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com