op ==
==
Precedence: 4 Associativity: none (a < b < c is an error)
Defined in
- 5.2 Precedence and associativity — Precedence and associativity
- 5.3 Overloading and user-defined operators — Overloading built-in operators — op declarations in impl
- 1.6 Operators and delimiters — + - * / % ** +% -% % +| -| | & | ^ ~ << >> && || !
- 5.4 Conditions — There is no ternary operator.
- 5.6 Loops — for accepts Iterable<T> (including iter<T>, collections, ranges); for await accepts Streamable<T>.
- 4.2 data — A field: visibility?
Examples
let kind = if n < 0 { "neg" } else if n == 0 { "zero" } else { "pos" }
if let User{ role: .Admin, name, .. } = u { greet(name) }
if x is Receipt { save(x) } // x is narrowed to Receiptfor u in users { … }
for (i, u) in users.enumerate() { … }
for i in 0..n where i % 2 == 0 { … } // filter
for await msg in input { … } // stream<T>
while cond { … }
while let x? = queue.pop() { … }
loop { if done { break result } } // loop is an expression
'outer: for a in xs { for b in ys { if a == b { break 'outer } } }Related diagnostics
chained-comparison, not-callable, not-overloadable, operator-decl, range-not-iterable, invalid-char, break-value, outside-loop, unknown-field