Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Reference  >  statement
Statements in the Rice

Statements

The statements are one of the things that make up the Rice code. Usually, it expresses some action to be carried out.

In the Rice, There are some single-statement and some compound-statement.

A single-statement is a statement to express some action to be carried out. It always ends with a semicolon.

A compound-statement is a statement to control the flow of execution. It will include other statements, and ends with an appropriate keyword.

Single-statements are the following seven types.


declaration statement

definition sentence

assignment statement

call statement

return statement

break statement

continue statement


Compound-statements are the following five types.


if statement

while statement

fromto statement

each statement

try statement


declaration statement

A declaration statement introduces a variable name to the program, and binds the type to the variable name.

A declaration statement is the following format.


typename identifier ;


A typename in a declaration statement is almost a simple type name.

For example,


int i;

string s;


However, list, dictionary, queue, and stack of collection types can specify a type name to hold inside.

For example,


list{int} listInt;

stack{string} stackString;


A collection type variable that is declared like above can not hold a element other than specified type.

A type of the elements to hold inside can be nested any number.

For example,


list{dictionary{long}} ldl;

stack{queue{list{bool}}} sqlb;


definition statement

A definition statement carry out the declaration and initialization of a variable at the same time.

A definition statement is the following format.


typename identifier = expression ;


The expression of the right side must return the address of the appropriate type instance.

assignment statement

An assignment statement is the assignment of the address that is returned by the right side expression to the left side expression.

An assignment statement is the following format.


expression = expression ;


If the left side expression ends with identifier or field name, the reference of the left side will be changed to the address that is returned by the right side expression.

If the left side expression ends with a setter name, An assignment statement is converted to a setter call, the right side expression will be an argument. Action of the setter depends on the implementation of the setter.

The expression of the right side must return the address of the appropriate type instance.

An assignment of the Rice is not an expression but a statement. It does not return the address of the instance. And therefore, it is impossible to repeat the assignment as in several languages.

For example,


int i;

int j;

int k;

i = j = k = 10;//Error!


call statement

If the semicolon followed to a single expression that ends with a method call, it is a call statement.

If a call statement ends with a method call after the dot operator, it call a method of an instance that is returned by the left side of the dot.

If there is not a dot operator in a call statement, it call a method of current instance.

return statement

The execution of the subroutine is stoped, and the control is returned to the invoker of the subroutine. If an expression follow after the return, the value returned by the expression is returned to the invoker as the return value of the subroutine. If there is not an expression after the return, void is returned to the invoker.

A return statement is the following format.


return ;

return expression ;


The return type must match the return type of the subroutine definition.

The above subroutine are the fitter, setter, getter, and method. There is no return value to the fitter and setter. Therefore, using return statement that have an expression at the fitter or setter will occur an error.

break statement

A break statement will move control to the next statement of the nearest loop statement that surround the break statement.

A break statement is the following format.


break ;


The above loop statement are the while, fromto, and each statement.

continue statement

A continue statement will move control to the first statement of the nearest loop statement that surround the continue statement.

A continue statement is the following format.


continue ;


The above loop statement are the while, fromto, and each statement.

if statement

A if statement is a statement to branch a flow of execution depending on conditions.

A if statement is the following format.


if(conditional expression)

statements

elseif(conditional expression)

statements

else

statements

endif


An expression in parentheses of the if clause or elseif clause is a conditional expression. If the conditional expression is true, the statements in its clause is executed. If the conditional expression is false, the same operation is repeated to the next elseif clause.

The elseif clause is able to exist any number in the if statement. If all conditional expression are false and there is a else clause, the statements in the else clause is executed.

The if statement have to end with the endif. The presence of elseif clause and the else clause is optional. The conditional expression have to be an expression that returns a bool.

A clause of the if statement generate a scope. Please refer to the manual about the scope.

while statement

A while statement is a statement to control a loop of execution depending on conditions.

A while statement is the following format.


while(conditional expression)

statements

endwhile


An expression in parentheses following to the while is a conditional expression. If the conditional expression is true, the control will move to the first statement in while statement. If the conditional expression is false, the control will move to the next statement of the endwhile.

When the control reaches to continue statement or endwhile, the control moves to the while, and repeats the execution from the evaluation of the condition expression.

When the control reaches to break statement, the control moves to the next statement of the endwhile.

The while statement have to end with the endwhile. The conditional expression have to be an expression that returns a bool.

A while statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the while statement, a while statement automatically defines the reserved variable __count.

__count is a variable of int. It is initialized with the number of loops that starts from zero.

__count does not cause the overflow like a normal int. If __count has exceeded the maximum value of the int, it will be automatically back to zero.

fromto statement

A fromto statement is a statement to control a loop of execution depending on loop index.

A fromto statement is the following format.


fromto(expression,expression)

statements

endfromto


First expression in parentheses following to the fromto is a start value of loop index. Scond expression is a end value of loop index.

Both expression have to be an expression that returns int, and it is determined at the beginning of fromto. The values are never changed while the loop.

If the start value is less than or equal to the end value. Loop index that was initialized to the start value is added 1 for each loop. If the loop index is greater than the end value, the control will move to the next statement of endfromto.

If the start value is greater than the end value. Loop index that was initialized to the start value is subtracted 1 for each loop. If the loop index is less than the end value, the control will move to the next statement of endfromto.

When the control reaches to continue statement or endfromto, the control moves to the fromto, and repeats the execution from the evaluation of the loop index.

When the control reaches to break statement, the control moves to the next statement of the endfromto.

A fromto statement have to end with the endfromto.

A fromto statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the fromto statement, a fromto statement automatically defines the reserved variable __count and __index.

__count is a variable of int. It is initialized with the number of loops that starts from zero.

__index is a variable of int. It is initialized with the current loop index value.

__count does not cause the overflow like a normal int. If __count has exceeded the maximum value of the int, it will be automatically back to zero.

each statement

A each statement is a statement to control a loop of execution depending on elements of a collection.

A each statement is the following format.


each(expression)

statements

endeach


A expression in parentheses following to the each is a specification of a collection, it have to return a list, dictionary, queue, or stack.

When the control reaches to continue statement or endeach, the control moves to the each, and repeats the execution to next element of the collection.

When the control reaches to break statement, the control moves to the next statement of the endeach.

An each statement have to end with the endeach.

A each statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the each statement, a each statement automatically defines the reserved variable __count and __value. In addition, if the collection is a dictionary, the reserved variable __key will be automatically defined.

__count is a variable of int. It is initialized with the number of loops that starts from zero.

__value is initialized with a element of the collection. Type of __value depends on type of the element.

__key is a variable of string. It is initialized with a key of the element.

__count does not cause the overflow like a normal int. If __count has exceeded the maximum value of the int, it will be automatically back to zero.

try statement

A try statement is a statement to branch a flow of execution depending on exception.

A try statement is the following format.


try

statements

catch

statements

endtry


If an exception has occurred in the try clause, it operates as follows. If a catch clause is exist, the control will move to the first statement in the catch clause. If a catch clause is not exist, the control will move to the next statement of endtry.

If an exception did not occur in the try clause, a catch clause is skipped, and the control will move to the next statement of endtry.

An try statement have to end with the endtry. The presence of catch clause is optional.

A clause of the try statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the catch clause, a try statement automatically defines the reserved variable __error. __error is a variable of error.

Next
Previous
Copyright © Rice All rights reserved.