Operators

Ki uses a familiar set of operators.

Boolean Operators

  • and: &&
  • or: ||
  • equivalent: ==
  • not: !
  • not equal: !=
  • less than: <
  • less than or equal to: <=
  • greater than: >
  • greater than or equal to: >=

Mathematical Operators

  • add: +
  • subtract: -
  • multiply: *
  • divide: /
  • modulus: %
  • exponent: **
  • increment: ++
  • decrement: --

Any of these (save ++ and --) can have a = appended to the end to assign the new value. For example:

fn main() {
    var x: 5

    x += 11
}

++ and -- are syntactic sugar for += 1 and -= 1, i.e. they culminate in an assignment. As such, they cannot be used in compound expressions, like y = x++. They can also only be used as suffixes, not prefixes.

Bitwise Operators

  • and: &
  • or: |
  • not: ~
  • xor: ^
  • shift left: <<
  • shift right: >>

Just as with the mathematical operators, any of these can also have a = appended to the end to assign the new value. For example:

fn main() {
    var x: 5

    x <<= 2
}