目录

unless statement

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

语法 (Syntax)

除非语句的语法如下 -

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

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

例子 (Example)

a = false
unless a === true do
   IO.puts "Condition is not satisfied"
   IO.puts "So this code block is executed"
end
IO.puts "Outside the unless statement"

上述程序产生以下结果 -

Condition is not satisfied
So this code block is executed
Outside the unless statement
↑回到顶部↑
WIKI教程 @2018