Fsharp-nested-if-statements

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

F#-ネストされたifステートメント

F#プログラミングでは、if/thenまたはif/then/elseステートメントをネストすることは常に有効です。つまり、1つの if または else if ステートメントを別の if または else if ステートメント内で使用できます。

構文

if expr then
   expr
   if expr then
      expr
   else
      expr
else
   expr

let a : int32 = 100
let b : int32 = 200

( *check the boolean condition using if statement* )

if (a = 100) then
( *if condition is true then check the following* )

   if (b = 200) then
      printfn "Value of a is 100 and b is 200\n"
printfn "Exact value of a is: %d" a
printfn "Exact value of b is: %d" b

あなたがプログラムをコンパイルして実行すると、次の出力が得られます-

Value of a is 100 and b is 200

Exact value of a is: 100
Exact value of b is: 200