Elixir-decision-if-else

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

Elixir-if elseステートメント

*if..else* ステートメントは、ブール式とそれに続く1つ以上のステートメントで構成されます。 さらに、1つ以上のステートメントを含む *else* ステートメントが続きます。

構文

*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キーワードの後のコードが実行されます。

流れ図

If Elseステートメント

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