Elixir - Unless 語句



一個 unless 語句包含一個布林表示式,後跟一條或多條語句。

語法

unless 語句的語法如下所示 −

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

如果布林表示式評估為 false,則除非語句中的程式碼塊將被執行。如果布林表示式評估為 true,則指定 unless 語句的 end 關鍵字之後的第一個程式碼集將被執行。

示例

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
elixir_decision_making.htm
廣告
© . All rights reserved.