- F# 基础教程
- F# - 首页
- F# - 概述
- F# - 环境设置
- F# - 程序结构
- F# - 基本语法
- F# - 数据类型
- F# - 变量
- F# - 运算符
- F# - 决策
- F# - 循环
- F# - 函数
- F# - 字符串
- F# - 可选类型
- F# - 元组
- F# - 记录
- F# - 列表
- F# - 序列
- F# - 集合
- F# - 映射
- F# - 判别联合
- F# - 可变数据
- F# - 数组
- F# - 可变列表
- F# - 可变字典
- F# - 基本 I/O
- F# - 泛型
- F# - 委托
- F# - 枚举
- F# - 模式匹配
- F# - 异常处理
- F# - 类
- F# - 结构体
- F# - 运算符重载
- F# - 继承
- F# - 接口
- F# - 事件
- F# - 模块
- F# - 命名空间
F# - 布尔运算符
下表显示了 F# 语言支持的所有布尔运算符。假设变量 A 为 true,变量 B 为 false,则 -
| 运算符 | 描述 | 示例 |
|---|---|---|
| && | 称为布尔 AND 运算符。如果两个操作数都不为零,则条件为真。 | (A && B) 为假。 |
| || | 称为布尔 OR 运算符。如果两个操作数中任何一个不为零,则条件为真。 | (A || B) 为真。 |
| 非 | 称为布尔 NOT 运算符。用于反转其操作数的逻辑状态。如果条件为真,则逻辑 NOT 运算符将使其为假。 | not (A && B) 为真。 |
示例
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
fsharp_operators.htm
广告