目录

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)

如果声明

例子 (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
↑回到顶部↑
WIKI教程 @2018