Gentee Programming Language > Documentation > Syntax Download documentation

Local Variables

A local variable is likely to be declared anywhere inside a function body as well as in nested blocks. Each variable must be given its own type declaration in a new line, that contains a specified type name and variable names separated by commas.

<variable declaration> ::= <variable name> ['['<expression> { [','] <expression>} ']'] [of <type name>]
<variable list> ::= <variable declaration> ['='<expression>','<variable list>] | <variable declaration> [[',']<variable list>]
<variables declaration> ::= <type name><variable list><end-of-line>

Variable arrays are declared in a peculiar way (for example, the arr type). So, you can specify its dimension and item type of the object. The number of dimensions and their size enclosed in square brackets follow the variable name. For the measures dimension the expression can be applied. If the array element type differs from uint, the keyword of and the element type name are inserted into the same line.
Local variables can be initialized at the same time they are declared. Moreover, the variable name list is a comma-delimited list. As for the variable of arr type, you may not initialize them in the way mentioned above.

str a = "This is a string", b= "The second string"
uint i = 1, j k = 3
arr myarr[ 10, 10] of byte

Numeric variables are initialized to zero by default. Otherwise, either the appropriate initialized method or the zero fill is applied.

The scope of a local variable extends from its declaration to the end of the block in which it was declared, including nested blocks.
Global and local variables are likely to be redefined; in other words, within a block a newly declared variable shares the same name as the variable previously declared. It is possible that the new variable may be of another type. The last-mentioned variable will be available till the end of the current block, and the previously declared variable becomes hidden. Once the block ends, the variable that was subsequently hidden is again available. Actually, the objects declared as local ones are automatically created when the block begins execution, and destroyed when the block ends. You can create objects with the help of the new service function. In this case, a programmer should keep an eye on deleting objects, using the destroy function.

{
uint a = 10
... // variable a is equal to 10

{
... // variable a is equal to 10
uint a = 3
...// variable a is equal to 3
{
... // variable a is equal to 3
}
]}
...// variable a is equal to 10
}

See also

    The Global Command. Declaring Global Variables


 Copyright © 2004-2006 Gentee Inc. All rights reserved.