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

Level 7. Operators: The Math Toolkit

Operators are the symbols that do things with your values.

Arithmetic (number crunching)

OperatorMeaningExampleResult
+Add3 + 47
-Subtract10 - 37
*Multiply5 * 210
/Divide10 / 33
%Remainder10 % 31

These operators work on both integers and floats:

fun main() {
  let price = 5
  let quantity = 3
  let total = price * quantity
  println(total)
}

Comparison (asking questions)

OperatorMeaningExampleResult
==Equal to?5 == 5true
!=Not equal?5 != 3true
>Greater than?10 > 5true
<Less than?3 < 7true
>=Greater or equal?5 >= 5true
<=Less or equal?4 <= 3false

Logic (combining questions)

OperatorMeaningExample
&&AND — both must be truex > 0 && x < 100
||OR — at least one must be truex == 0 || x == 1

🎯 Try it: Write a fun main() that computes how many seconds are in an hour (60 × 60).