Assignment statement

An assignment statement assigns an instance to the lvalue.


Table of contents:


Format

Lvalue

Assignment symbol =

Expression

Semicolon

Example

Format

The format is:


lvalue = expression ;


The lvalue is things that can be placed on the left side of the assignment symbol. In Rice, they are variables, fields, expressions that end with a setter, and expressions that end with an indexer operator.

The lvalue will be changed with an instance returned by the expression on the right side of the assignment symbol.


If the lvalue ends with a variable or field, changes the address referenced by the lvalue.

If the lvalue ends with a setter, it is converted to a setter call.

If the lvalue ends with an indexer operator, changes an item of corresponding list class.

Lvalue

The lvalue is things that can be placed on the left side of the assignment symbol. In Rice, they are variables, fields, expressions that end with a setter, and expressions that end with an indexer operator.

Assignment symbol =

This is a symbol for changing the lvalue.

Expression

The expression creates an instance that changes the lvalue. The class of the generated instance must be the same as the lvalue.

As an exception, when assigning a numeric class with a small range to a numeric class with a large range, you can assign even if both classes are different.


real rr;

rr = 10L; // Assigns the long value to the real.

rr = 10; // Assigns the int value to the real.

long ll;

ll = 10; // Assigns the int value to the long.


In this case, a new instance of the lvalue class is created based on the instance returned by the right side, and it is assigned.

Semicolon

The end of a assignment statement is represented by a semicolon.

Example

1:

class example

2:

int var1;

3:

closed setter VarSetter(int val)

4:

var1 = val; // ♦1

5:

es

6:

open method void someMethod(int arg)

7:

this.VarSetter = arg; // ♦2

8:

list someList = new list("{1, 2, 3}");

9:

someList[0] = 4; // ♦3

10:

em

11:

ec

♦1 : Lvalue is the field.

♦2 : Lvalue is the expression that ends with the setter.

♦3 : Lvalue is the expression that ends with the indexer operator.

Copyright © Rice All rights reserved.