Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Tutorial  >  literals
Literals

Purpose of this chapter.

We will learn about the literals which is the elements that make up the statement.

Constant value.

A literal is a constant that is written directly in the code.

For example.


int i = 10;

string s = "literal";


A value is directly written like the right side of the above examples.


Literals of the Rice are the following five types.

int literal.

long literal.

real literal.

string literal.

bool literal.

A literal returns an instance, so you can call a member via a literal.

For example.


int length = "ggggg".Length;


The right side of the above example returns 5, it is the length of the string.

int literal.

An int literal is a positive integer written directly in the code.

The range is from 0 to the maximum of the int class(2,147,483,647).

There is no negative literal. If you need a negative number, use the unary minus operator for the literal.

An exception is thrown if the int literal exceeds the above range.

An int literal is the following formats.


A numeric value that a first letter is a digit other than zero and followed by zero or more digits.

For example,

123


A numeric value that a first letter is a digit other than zero and followed by zero or more digits and followed by an upper case I.

For example,

123I


A single zero.

For example,

0

The following number is not a literal.


A numeric value that a first letter is a zero and followed by 1 or more digits.

For example,

0123

long literal.

An long literal is a positive integer written directly in the code.

The range is from 0 to the maximum of the long class(9,223,372,036,854,775,807).

There is no negative literal. If you need a negative number, use the unary minus operator for the literal.

An exception is thrown if the long literal exceeds the above range.

An long literal is the following formats.


A numeric value that a first letter is a digit other than zero and followed by zero or more digits and followed by an upper case L.

For example,

123L


A numeric value that a first letter is zero and followed by an upper case L.

For example,

0L

real literal.

An real literal is a positive real number written directly in the code.

The range is roughly from +5.0e−324 to +1.7e308.

There is no negative literal. If you need a negative number, use the unary minus operator for the literal.

The real literal is evaluated as positive infinity if it is bigger than the above maximum value. The real literal evaluated as 0 if it is smaller than the above minimum value.

An real literal is the following formats.


A numeric value that a first letter is a digit other than zero and followed by zero or more digits and followed by dot and followed by zero or more digits.

For example,

123.005


A numeric value that a first letter is zero and followed by dot and followed by zero or more digits.

For example,

0.005


A numeric value that a first letter is dot and followed by zero or more digits.

For example,

.005

Zero in the real literal is expressed as 0.0.

string literal.

A string literal is a string that repeats characters other than double quotes that surrounded by double quotes.

For example,

"Other than double quotes"

bool literal.

A bool literal is a boolean value written directly in a code. The keyword true and false are used in order to represent bool literals.

For example,

true

false

Next
Previous
Copyright © Rice All rights reserved.