Fsharp-boolean-operators

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

F#-ブール演算子

次の表は、F#言語でサポートされているすべてのブール演算子を示しています。 変数Aが true を保持し、変数Bが false を保持すると仮定します-

Operator Description Example
&& Called Boolean AND operator. If both the operands are non-zero, then condition becomes true. (A && B) is false.
Called Boolean OR Operator. If any of the two operands is non-zero, then condition becomes true. (A
B) is true. not Called Boolean NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

let mutable a : bool = true;
let mutable b : bool = true;

if ( a && b ) then
   printfn "Line 1 - Condition is true"
else
   printfn "Line 1 - Condition is not true"

if ( a || b ) then
   printfn "Line 2 - Condition is true"
else
   printfn "Line 2 - Condition is not true"

( *lets change the value of a* )

a <- false
if ( a && b ) then
   printfn "Line 3 - Condition is true"
else
   printfn "Line 3 - Condition is not true"

if ( a || b ) then
   printfn "Line 4 - Condition is true"
else
   printfn "Line 4 - Condition is not true"

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

Line 1 - Condition is true
Line 2 - Condition is true
Line 3 - Condition is not true
Line 4 - Condition is true