Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法让 Ruby 程序一直执行直到程序出错?当程序返回错误时,我希望我的循环停止。谢谢
无限循环可以提供帮助吗?
while true do your code end
如果您的代码抛出错误,则循环停止。
这是另一个例子。将运行无限次,直到异常出现并处理您的异常,然后退出表单代码。
inc = 5 while true do begin puts 4/inc inc-=1 rescue Exception=> e puts e exit end end