Elixir-decision-unless-else

提供:Dev Guides
移動先:案内検索

エリクサー-他に述べない限り

*unless..else* ステートメントは、ブール式とそれに続く1つ以上のステートメントで構成されます。 さらに、独自のステートメントブロックを持つelseステートメントが続きます。

構文

*unless..else* ステートメントの構文は次のとおりです-
unless boolean-statement do
   #Code to be executed if condition is false
else
   #Code to be executed if condition is true
end

ブール式の評価が false の場合、unlessステートメント内のコードブロックが実行されます。 ブール式の評価がtrueの場合、指定された場合を除き、指定されたキーワードの else キーワードの後のコードが実行されます。

a = false
unless a === false do
   IO.puts "Condition is not satisfied"
else
   IO.puts "Condition was satisfied!"
end
IO.puts "Outside the unless statement"

上記のプログラムは、次の結果を生成します。

Condition was satisfied!
Outside the unless statement