Arithmetic

Arithmetic Operators

Arithmetic operators perform mathematical calculations on numeric values. The values they operate on are called operands, and the result is a new value.

For a broader introduction to operators, see Operators.

Addition#

The + operator adds two values together.

int a = 3;
int b = 4;
int result = a + b;  // 7
a = 3
b = 4
result = a + b  # 7
let a = 3;
let b = 4;
let result = a + b;  // 7

Subtraction#

The - operator subtracts the right operand from the left.

Operators

An operator is a symbol that performs an operation on one or more values. The values it operates on are called operands, and the result is a new value.

  operand   operator   operand
     5          +          3
              result
                8

Types of Operators#

Arithmetic Operators#

Perform mathematical calculations — addition, subtraction, multiplication, division, modulo.

See Arithmetic Operators for a full explanation and examples.

Comparison Operators#

Compare two values and produce a true or false result. Used to build conditions in if/else statements and loops.