ProtoLang.net

Reference: Plus

☰ Hide Sidebar
TOKEN PLUS
ALIAS +

The Plus operator adds two numeric values together. Mixing Data Types (e.g. Integers and Floats) is not allowed and the Plus 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 PLUS:

PRINT VALUE PLUS VALUE

Examples

Example: Adding Integer Literals

NEW INT x = 42 + 7
PRINT x // Displays "49"

Example: Adding Float Literals

NEW FLOAT x = 3.14 + 2.86
PRINT x // Displays "6.0"

Example: Adding Integer Variables

NEW INT x = 10
NEW INT y = 5
PRINT x + y // Displays "15"

Example: Incrementing an Integer counter

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

Example: Using Plus in a Loop with Integers

NEW INT i = 1
NEW INT result = 0
WHILE i <= 5
    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

Error: Using + on Strings

PRINTLN "Hello" + "World" // Type error! The Plus operator is used for arithmetic. Strings use the Concatenate operator instead