-
Data Structures
-
Iteration
-
Functions
-
Mathematics
-
Examples
-
Exercises
Modulo instruction
The modulo instruction is an arithmetic instruction using the % character.
It is used like other arithmetic instructions such as + and -
It returns the remainder, after division by a certain number.
This divides 5 by 2, which can be divided twice with a remainder of 1.
This is not really used much, but it is used in lots of programming challenges. Particularly, we can use it to test if something is divisible.
A number can be evenly divided by another number if there is no remainder.
is_four_even = (4 % 2 == 0)
or the more general function