返回介绍

if statement

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

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

语法 (Syntax)

if语句的语法如下 -

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

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

流程图 (Flow Diagram)

如果声明

例子 (Example)

a = true
if a === true do
   IO.puts "Variable a is true!"
   IO.puts "So this code block is executed"
end
IO.puts "Outside the if statement"

上述程序将产生以下结果 -

Variable a is true!
So this code block is executed
Outside the if statement

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

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

发布评论

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