Scratch for Java

Operators::mod()

"mod" is an abbreviation for "modulo". Modulo returns what is left over when the first input is divided by the second.

The answer takes the sign of the second input, as the Scratch block does, so mod(-7, 3) is 2 rather than the -1 Java's own % would give. That is what makes it useful for wrapping a value into a range: a sprite whose x has gone negative still lands somewhere sensible.

Examples

View on GitHub

Syntax

Java

.mod(x, y)
.mod(x, y)

Scratch

((x) mod (y))

Parameters

Name Data Type Description
x double first value
y double second value

Return

double

mod()

Create Shareable URL

Select Sections