Elixir-decision-if-statement

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

Elixir-Ifステートメント

ifステートメントは、ブール式とそれに続く1つ以上のステートメントで構成されます。

構文

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

ブール式の評価がtrueの場合、ifステートメント内のコードブロックが実行されます。 ブール式の評価がfalseの場合、指定されたifステートメントのendキーワードの後の最初のコードセットが実行されます。

流れ図

Ifステートメント

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