...

/

Operators: Arithmetic, In, and Range

Operators: Arithmetic, In, and Range

Explore and understand arithmetic operators, range operators, and the in operator for collections and ranges.

Arithmetic operators

Let’s start with arithmetic operators, like plus or times. These are easiest for the Kotlin compiler because it just needs to transform the left column to the right.

Expression

Translation

a+b

a.plus(b)

a-b

a.minus(b)

a*b

a.times(b)

a/b

a.div(b)

a%b

a.rem(b)

a..b

a.rangeTo(b)

Points to remember:

  • The % operator translates to rem, which is a short form of remainder. This operator returns the remainder left over when one operand is ...