Short-curcuit boolean operators.

This commit is contained in:
Stephen Chung
2020-03-02 12:08:03 +08:00
parent bedfe55005
commit 22a505b57b
6 changed files with 187 additions and 40 deletions

View File

@@ -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