EnglishРусский  

Ads

Installer and installation software
Commercial and Freeware installers.

Local variables

Local variables serve for temporary storage of intermediate results when a function or a method is executed. A local variable can be declared in any part of the function body including nested blocks taken in braces. 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.

If the variable type supports the use of of and brackets, you can specify those additional parameters when you describe a local variable. Besides, number variables, along with strings str and binary data buf can be initialized at the moment when they are described with the help of the assignment operation '='. When you initialize variables, you can use macroexpressions. By default, the variable is initialized with zeroes or by calling the corresponding initialization function.

func myfunc( uint param, str name )
{
   str a b = "My string" + name, c
   uint i = 25 * param + 3
   uint k = 10, l = 2 
   arr x[ k, l ] of uint
   arrstr months = %{"January", "February", "March", "April", "May",
                     "June", "July", "August", "September", "October",
                     "November", "December" }
   ...
}

Scope of local variables

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. As local variables are deleted when we exit the function, you can only return numeric local variables.

func myfunc
{
   uint a = 10
   ... // a == 10
   {      
      ... // a == 10
      uint a = 3
      ... // a == 3
      while ... 
      {
         ... // a == 3
      }
      ... // a == 3
   }
   ... // a == 10 
}

Related links