Swift Arithmetic Operators
Swift Arithmetic Operators
Use +, -, *, and / to add, subtract, multiply and divide.
Integer division truncates toward zero.
Examples
These examples show addition, subtraction, multiplication and integer division.
Example
let a = 7, b = 3
print(a - b)
print(a * b)
print(a / b) // integer division
This example demonstrates arithmetic with integers.
Remainder Operator
The remainder operator % gives the leftover after integer division.
Use % to check divisibility or cycle through a fixed range.