- Rust 教程
- Rust - 主页
- Rust - 简介
- Rust - 环境设置
- Rust - HelloWorld 示例
- Rust - 数据类型
- Rust - 变量
- Rust - 常量
- Rust - 字符串
- Rust - 运算符
- Rust - 决策制定
- Rust - 循环
- Rust - 函数
- Rust - 元组
- Rust - 数组
- Rust - 所有权
- Rust - 借用
- Rust - 切片
- Rust - 结构体
- Rust - 枚举
- Rust - 模块
- Rust - 集合
- Rust - 错误处理
- Rust - 泛型
- Rust - 输入输出
- Rust - 文件输入/输出
- Rust - 软件包管理器
- Rust - 迭代器和闭包
- Rust - 智能指针
- Rust - 并发性
- Rust 实用资源
- Rust - 快速指南
- Rust - 实用资源
- Rust - 讨论
Rust - 关系运算符
关系运算符用来测试或定义两个实体之间的关系类型。关系运算符用来比较两个或更多个值。关系运算符会返回一个布尔值 - 真或假。
假设 A 的值为 10,B 的值为 20。
| 序号 | 运算符 | 说明 | 示例 |
|---|---|---|---|
| 1 | > | 大于 | (A > B) 为假 |
| 2 | < | 小于 | (A < B) 为真 |
| 3 | >= | 大于或等于 | (A >= B) 为假 |
| 4 | <= | 小于或等于 | (A <= B) 为真 |
| 5 | == | 等 | (A == B) 为假 |
| 6 | != | 不等 | (A != B) 为真 |
示例
fn main() {
let A:i32 = 10;
let B:i32 = 20;
println!("Value of A:{} ",A);
println!("Value of B : {} ",B);
let mut res = A>B ;
println!("A greater than B: {} ",res);
res = A<B ;
println!("A lesser than B: {} ",res) ;
res = A>=B ;
println!("A greater than or equal to B: {} ",res);
res = A<=B;
println!("A lesser than or equal to B: {}",res) ;
res = A==B ;
println!("A is equal to B: {}",res) ;
res = A!=B ;
println!("A is not equal to B: {} ",res);
}
输出
Value of A:10 Value of B : 20 A greater than B: false A lesser than B: true A greater than or equal to B: false A lesser than or equal to B: true A is equal to B: false A is not equal to B: true
rust_operators.htm
广告