Elixir-decision-if-statement

提供:Dev Guides
2020年6月22日 (月) 22:53時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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