如果满足给定条件则结束 ruby​​ 程序

发布于 2024-11-25 13:26:53 字数 254 浏览 1 评论 0原文

基本上,我只是想在满足特定条件时阻止程序运行其余的行。

unless raw_information.first
  puts "No results were returned for that query"
  break
end

但是,在程序运行之前我收到此错误:

无效中断 编译错误(语法错误)

执行此操作的正确方法是什么?

Basically, I am just trying to stop the program from running the rest of the lines if a certain condition is met.

unless raw_information.first
  puts "No results were returned for that query"
  break
end

However, before the program even runs I get this error:

Invalid break
compile error (SyntaxError)

What is the proper way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最后的乘客 2024-12-02 13:26:53
abort("No results were returned for that query") unless condition

或者

unless condition
  abort("No results were returned for that query")
end
abort("No results were returned for that query") unless condition

or

unless condition
  abort("No results were returned for that query")
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文