Literals#
Literals are a way of directly putting raw data in your code.
Primitive Literals#
Primitive literals hold simple data of primitive data types.
Boolean#
Booleans only have 2 values, each of which has its own literal: true
and false
.
Numbers#
Name |
Data Type |
Prefix/Suffix |
Range |
---|---|---|---|
Decimal Number |
|
|
|
Hexadecimal Number |
|
|
|
Binary Number |
|
|
|
Octal Number |
|
|
|
Long Decimal Number |
|
|
|
Long Hexadecimal Number |
|
|
|
Long Binary Number |
|
0b prefix + L suffixOR
Lb /bL suffix |
|
Long Octal Number |
|
0o prefix + L suffixOR
Lo /oL suffix |
|
Note
If the integer portion of a number is 0, the leading 0 can be omitted (ex. .9 == 0.9
).
It can be easier to read if you put the 0 there, though.
Number Spacers#
Added in version 2.55.9.
You may place spacers _
between any 2 digits, which have no effect, but can help
make the number more readable. Example:
150_000 == 150000
150_200_500L == 150200500L
0x10_FF == 0x10FF
0b1000_1000 == 0b10001000
Character Literals#
A character literal represents a single character value. It is represented as a single character,
between two single-quotes (ex. 'a'
).
Additionally, escape characters can be used to insert
special characters, including '
and \
.
Complex Literals#
These literals represent more complex data. They may not be considered ‘compile-time constant’ in all circumstances.
String / Array Literals#
Difference between String/Array ‘Literals’ and ‘Initializers’#
There is a distinction between an array with an initializer (which looks and acts effectively identical to a string literal), and a loose string/array literal that is not an initializer. Notably, a loose literal creates a temporary array, which will stop existing almost immediately. (These are useful, for example, in function call parameters, where they would stop existing after the whole call).
Escape Characters#
Some special characters must be escaped with a backwards slash followed by an escape character.
Character |
Meaning |
---|---|
|
Alert (Beep, Bell) |
|
Backspace |
|
Formfeed Page Break |
|
Newline (Line Feed) |
|
Carriage Return |
|
Horizontal Tab |
|
Vertical Tab |
|
Backslash |
|
Single-quote |
|
Double-quote |
|
Question Mark |
|
Insert arbitrary hex character code |