当前位置: 首页 > 文档资料 > Elixir 中文教程 >

if statement

优质
小牛编辑
121浏览
2023-12-01

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