- Rust Tutorial
- Rust - Home
- Rust - Introduction
- Rust - Environment Setup
- Rust - HelloWorld Example
- Rust - Data Types
- Rust - Variables
- Rust - Constant
- Rust - String
- Rust - Operators
- Rust - Decision Making
- Rust - Loop
- Rust - Functions
- Rust - Tuple
- Rust - Array
- Rust - Ownership
- Rust - Borrowing
- Rust - Slices
- Rust - Structure
- Rust - Enums
- Rust - Modules
- Rust - Collections
- Rust - Error Handling
- Rust - Generic Types
- Rust - Input Output
- Rust - File Input/ Output
- Rust - Package Manager
- Rust - Iterator and Closure
- Rust - Smart Pointers
- Rust - Concurrency
- Rust Useful Resources
- Rust - Quick Guide
- Rust - Useful Resources
- Rust - Discussion
Rust - Logical Operators
Logical Operators are used to combine two or more conditions. Logical operators too, return a Boolean value. Assume the value of variable A is 10 and B is 20.
Sr.No | Operator | Description | Example |
---|---|---|---|
1 | && (And) | The operator returns true only if all the expressions specified return true | (A > 10 && B > 10) is False |
2 | ||(OR) | The operator returns true if at least one of the expressions specified return true | (A > 10 || B >10) is True |
3 | ! (NOT) | The operator returns the inverse of the expression’s result. For E.g.: !(>5) returns false | !(A >10 ) is True |
Illustration
fn main() { let a = 20; let b = 30; if (a > 10) && (b > 10) { println!("true"); } let c = 0; let d = 30; if (c>10) || (d>10){ println!("true"); } let is_elder = false; if !is_elder { println!("Not Elder"); } }
Output
true true Not Elder
rust_operators.htm
Advertisements