math.mod

From ComputerCraft
Jump to: navigation, search

math.mod
Function
Syntax
math.mod()
Returns number
API math
Source Lua (source)

Return the remainder of dividing x by y. This has the same behaviour as the % operator.

ExampleExampleTest if user input is even
Read a line from the user, then print if it is evenly divisible by 2.
Code
print(math.mod(tonumber(read()), 2) == 0)
Output Depends on what the user wrote. For instance, if they were to enter 5, the value printed would be false.