目录

if..else statement

if..else语句由一个布尔表达式后跟一个或多个语句组成。 接下来是带有一个或多个语句的else语句。

语法 (Syntax)

if..else语句的语法如下 -

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

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

流程图 (Flow Diagram)

如果是其他声明

例子 (Example)

a = false
if a === true do
   IO.puts "Variable a is true!"
else
   IO.puts "Variable a is false!"
end
IO.puts "Outside the if statement"

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

Variable a is false! 
Outside the if statement
↑回到顶部↑
WIKI教程 @2018