🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators Integer::mod ( i : Integer ) : Integer
This page was created by Peter on 2019-12-18. Last edited by Wikiadmin on 2026-07-29.

You can use mod in an OCL expression when you need the integer remainder after dividing one Integer by another.

Signature

Integer::mod ( i : Integer ) : Integer

self is the dividend (the value being divided), and i is the divisor (the value to divide by). The operation returns the remainder as an Integer.

Syntax

In MDriven, use mod as an infix operator, in the same style as + or -:

dividend mod divisor

For example:

10 mod 3

The result is 1: 3 fits into 10 three whole times, leaving 1.

Examples

Expression Integer division Remainder returned by mod
10 mod 3 10 divided by 3 gives a quotient of 3 1
12 mod 4 12 divided by 4 gives a quotient of 3 0
7 mod 2 7 divided by 2 gives a quotient of 3 1

A result of 0 means that the dividend is evenly divisible by the divisor. For example, you can test whether 12 is divisible by 4 with:

12 mod 4 = 0

Use with integer division

Use mod when you need the part left over from integer division. Use Integer::div when you need the whole-number quotient instead.

For the same values, the two operations provide different parts of the division:

10 div 3  -- 3
10 mod 3  -- 1

The quotient and remainder describe the original value: 10 = (3 * 3) + 1.

See also