ProtoLang.net

Reference: Modulo

☰ Hide Sidebar
TOKEN MODULO
ALIAS %

The Modulo operator calculates the remainder after dividing one numeric value by another. Mixing Data Types (e.g. Integers and Floats) is not allowed and the Modulo operator does not work on Strings or Booleans.

Syntax

The short syntax structure uses the % symbol:

PRINT VALUE % VALUE

The long syntax structure uses the word MODULO:

PRINT VALUE MODULO VALUE

Examples

Example: Finding Remainder with Integer Literals

NEW INT x = 10 % 3
PRINT x // Displays "1"

Example: Finding Remainder with Float Literals

NEW FLOAT x = 5.5 % 2.0
PRINT x // Displays "1.5"

Example: Checking for Even Numbers

NEW INT num = 8
PRINT num % 2 // Displays "0"

Example: Cycling through a range

NEW INT counter = 11
SET counter = counter % 10
PRINT counter // Displays "1"

Example: Using Modulo in a Loop

NEW INT i = 1
WHILE i <= 10
    IF i % 2 == 0
        PRINTLN i // Displays even numbers only
    END IF
    SET i = i + 1
END WHILE

Common Errors

Error: Mixing Integer and Float Literals

NEW INT x = 7
NEW FLOAT y = 3.0
PRINT x % y // Type error! Cannot mix Integer and Float Data Types