- 教程
- 概述
- 环境
- Basic 语法
- 数据类型
- 变量
- 运算符
- 模式匹配( Pattern Matching)
- 决策( Decision Making)
- Strings( Strings)
- Char Lists( Char Lists)
- 列表和元组( Lists and Tuples)
- 关键字列表( Keyword Lists)
- Maps
- 模块( Modules)
- 别名( Aliases)
- 功能( Functions)
- 递归
- 循环
- Enumerables( Enumerables)
- Streams( Streams)
- Structs( Structs)
- 协议 Protocols
- File I/O
- 进程( Processes)
- Sigils( Sigils)
- 理解( Comprehensions)
- Typespecs( Typespecs)
- 行为( Behaviours)
- 错误处理( Errors Handling)
- Macros( Macros)
- (库)Libraries
- 有用的资源
- 讨论
- Show 例子
- Show 例子
- Show 例子
- Show 例子
- Show 例子
- if statement
- if..else statement
- unless statement
- unless..else statement
- cond
- case
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
if statement
if语句由一个布尔表达式后跟一个或多个语句组成。
语法 (Syntax)
if语句的语法如下 -
if boolean-statement do
#Code to be executed if condition is satisfied
end
如果布尔表达式的计算结果为true,那么将执行if语句中的代码块。 如果布尔表达式的计算结果为false,则将执行给定if语句的end关键字之后的第一组代码。
流程图 (Flow Diagram)
![如果声明](http://www.wenjiangs.com/wp-content/uploads/2021/docimg8/332-rojtpcts5fy.jpg)
例子 (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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论