当前位置: 首页 > 文档资料 > F# 中文教程 >

Show Example

优质
小牛编辑
121浏览
2023-12-01

下表显示了F#语言支持的所有布尔运算符。 假设变量A保持为true ,变量B保持为false,则 -

操作者描述
&&称为布尔AND运算符。 如果两个操作数都不为零,则条件成立。(A && B)是假的。
||称为布尔OR运算符。 如果两个操作数中的任何一个非零,则条件变为真。(A || B)是真的。
not称为布尔NOT运算符。 用于反转其操作数的逻辑状态。 如果条件为真,则Logical NOT运算符将为false。不(A && B)是真的。

例子 (Example)

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