Rust - 关系运算符
关系运算符测试或定义两个实体之间的关系类型。 关系运算符用于比较两个或多个值。 关系运算符返回一个布尔值 − true 或 false。
假设 A 的值为 10,B 的值为 20。
| Sr.No | 运算符 | 描述 | 示例 |
|---|---|---|---|
| 1 | > | 大于 | (A > B) 为 False |
| 2 | < | 小于 | (A < B) 为 True |
| 3 | >= | 大于或等于 | (A >= B) 为 False |
| 4 | <= | 小于或等于 | (A <= B) 为 True |
| 5 | == | 等于 | (A == B) 为 fals |
| 6 | != | 不等于 | (A != B) 为 True |
示例
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

