返回介绍

unless statement

发布于 2021-05-25 13:29:46 字数 620 浏览 902 评论 0 收藏 0

unless语句由一个布尔表达式后跟一个或多个语句组成。

语法 (Syntax)

除非语句的语法如下 -

unless boolean-statement do
   #Code to be executed if condition is false
end

如果布尔表达式的计算结果为false ,则将执行unless语句中的代码块。 如果布尔表达式的计算结果为true,则将执行给定除非语句的结束关键字之后的第一组代码。

例子 (Example)

a = false
unless a === true do
   IO.puts "Condition is not satisfied"
   IO.puts "So this code block is executed"
end
IO.puts "Outside the unless statement"

上述程序产生以下结果 -

Condition is not satisfied
So this code block is executed
Outside the unless statement

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文