Reputation: 711
Do &&
and ||
stop evaluating as soon as a result is known?
In other words will (true == true) || (true == false)
not evaluate the right side because the whole expression is known to be true
after only evaluating the left side.
Upvotes: 25
Views: 8291
Reputation: 711
Yes.
From the Rust reference:
fn main() {
let x = false || true; // true
let y = false && panic!(); // false, doesn't evaluate `panic!()`
}
Upvotes: 36