Short-curcuit boolean operators.
This commit is contained in:
16
README.md
16
README.md
@@ -387,12 +387,26 @@ fn main() {
|
||||
let x = 3;
|
||||
```
|
||||
|
||||
## Operators
|
||||
## Numeric operators
|
||||
|
||||
```rust
|
||||
let x = (1 + 2) * (6 - 4) / 2;
|
||||
```
|
||||
|
||||
## Boolean operators
|
||||
|
||||
Double boolean operators `&&` and `||` _short-circuit_, meaning that the second operand will not be evaluated if the first one already proves the condition wrong.
|
||||
|
||||
Single boolean operators `&` and `|` always evaluate both operands.
|
||||
|
||||
```rust
|
||||
this() || that(); // that() is not evaluated if this() is true
|
||||
this() && that(); // that() is not evaluated if this() is false
|
||||
|
||||
this() | that(); // both this() and that() are evaluated
|
||||
this() & that(); // both this() and that() are evaluated
|
||||
```
|
||||
|
||||
## If
|
||||
|
||||
```rust
|
||||
|
Reference in New Issue
Block a user