Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Comparison and Logical Operators

Comparison Operators

All return bool. Work with all integer types. Sign-aware: i32 uses signed comparison, u32 uses unsigned.

OperatorExample
==a == b
!=a != b
<a < b
<=a <= b
>a > b
>=a >= b

Note

Enum values support == and != only.

Logical Operators

Operate on bool values:

OperatorExample
&&a && b
||a || b
!!a

Example

pub fn is_in_range(x: i32, lo: i32, hi: i32) -> bool {
    return (x >= lo) && (x <= hi);
}