Variables

Parent Previous Next

Variables.

Variables are declared in the function code block.


When declaring variables of a given type, each declaration can include one or more variables as presented here:


 Function Foo()

 {

   Integer i;

   Integer j, k;

 }


A variable can be declared and initialized simultaneously. The variable receives the default value, unless it is explicitly assigned another value. In this example the functions Foo1 and Foo2 accomplish the same - however Foo2 only uses a single statement:


 Function Foo1()

 {

   Integer i, j; //Here they are both implicit initialized to zero;

   i := 1;

   j := 2;

 }


 Function Foo2()

 {

   Integer i := 1, j := 2;

 }


Once a variable is declared it can immediately be used in later sub-statements within the same declaration:


 Function Foo()

 {

   Integer i := 3, j := 4 * i; //Now j == 12;

 }



Redeclaration.

A variable can only be declared once in a code block. However, it may be redeclared in another code block on an inner level:


 Function Foo()

 {

   Integer myVar := 10;

   If True Then

   {

     //Now  myVar is redeclared to be a string.

     //It will exist until we leave the block.

     //Until then the previous myVar is not accessible.

     String myVar := "Hello";

   }

   Integer i := myVar; //Now i == 10;

 }


Please notice that redeclaration has no security implications at all. It only exists for the programmers convenience.