ProtoLang.net

Reference: Minus

☰ Hide Sidebar
TOKEN MINUS
ALIAS -

The Minus operator subtracts one numeric value from another. Mixing Data Types (e.g. Integers and Floats) is not allowed and the Minus 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 MINUS:

PRINT VALUE MINUS VALUE

Examples

Example: Subtracting Integer Literals

NEW INT x = 42 - 7
PRINT x // Displays "35"

Example: Subtracting Float Literals

NEW FLOAT x = 3.14 - 2.86
PRINT x // Displays "0.28"

Example: Subtracting Integer Variables

NEW INT x = 10
NEW INT y = 5
PRINT x - y // Displays "5"

Example: Decrementing an Integer counter

NEW INT counter = 0
SET counter = counter - 1
PRINT counter // Displays "-1"

Example: Using Minus in a Loop with Integers

NEW INT i = 5
NEW INT result = 0
WHILE i >= 1
    SET result = result + i
    SET i = i - 1
END WHILE
PRINT result // Displays "15"

Common Errors

Error: Mixing Integer and Float Literals

NEW INT x = 5
NEW FLOAT y = 2.5
PRINT x - y // Type error! Cannot mix Integer and Float Data Types