ProtoLang.net

Reference: Boolean

☰ Hide Sidebar
TOKEN BOOLEAN
ALIAS BOOL

The Boolean Data Type is used to represent logic. There are exactly two valid values (literals) for booleans: True and False. Booleans can be used in Expressions. Boolean expressions cannot contain Integers, Floats or Strings.

Syntax

The short syntax structure uses the word BOOL:

NEW BOOL VARIABLE = VALUE

The long syntax structure uses the word BOOLEAN:

NEW BOOLEAN VARIABLE EQUAL TO VALUE

Examples

Example: Creating Boolean and setting Value to Literal

NEW BOOL x = TRUE
PRINTLN x // Displays "TRUE"

Example: Creating Boolean and setting Value to Variable

NEW BOOL x = TRUE
NEW BOOL y = x
PRINTLN y // Displays "TRUE"

Example: Creating Boolean and setting Value to Expression

NEW BOOL x = 5 > 10 // This line asks the queston: Is 5 GREATER THAN 10?
PRINTLN x // Displays "FALSE"

Example: Printing Boolean Expressions

PRINTLN 5 > 10 // This line asks the queston: Is 5 GREATER THAN 10? (FALSE)
PRINTLN 5 < 10 // This line asks the queston: Is 5 LESS THAN 10? (TRUE)
PRINTLN 5 == 10 // This line asks the queston: Is 5 EQUAL TO 10? (FALSE)
PRINTLN 5 != 10 // This line asks the queston: Is 5 NOT EQUAL TO 10? (TRUE)

Common Errors

Error: Creating Boolean and setting to Integer Literal

NEW BOOL x = 1 // Runtime error! Cannot assign Integer Literal to Boolean Data Type
PRINTLN x // This line is not executed because the program crashed!

Error: Creating Boolean and setting to Float Literal

NEW BOOL x = 1.0 // Runtime error! Cannot assign Float Literal to Boolean Data Type
PRINTLN x // This line is not executed because the program crashed!

Error: Creating Boolean and setting to String Literal

NEW BOOL x = "TRUE" // Runtime error! Cannot assign String Literal to Boolean Data Type
PRINTLN x // This line is not executed because the program crashed!