Variable Categories

There are five kinds of variables:

  • Script variables. These are defined in the Cisco Unified CCX Script Editor and are accessible from within expressions (except for prompt and grammar templates). They exist for the life of the script.

  • Array components. These are unnamed variables that are created and initialized to default values whenever a new object that is an array is created. The array components effectively cease to exist when the array is no longer referenced.

  • Complex expression block parameters. These are name argument values passed to a complex block expression. For every parameter declared in a method declaration, a new parameter variable is created each time that method expression is evaluated. The new variable is initialized with the corresponding argument value from the expression invocation. The block parameter effectively ceases to exist when the execution of the body of the block expression is complete.

  • An exception-handler parameter. This is created each time an exception is caught by a catch clause of a try statement. The new variable is initialized with the actual object associated with the exception. The exception-handler parameter effectively ceases to exist when execution of the block associated with the catch clause is complete.

  • Local variables. These are declared by local variable declaration statements. Whenever the flow of control enters a block or for statement, a new variable is created for each local variable declared in a local variable declaration statement immediately contained within that block or for statement. A local variable declaration statement may contain an expression which initializes the variable. The local variable with an initializing expression is not initialized, however, until the local variable declaration statement that declares it is executed. The rules of definite assignment prevent the value of a local variable from being used before it has been initialized or otherwise assigned a value. The local variable effectively ceases to exist when the execution of the block or for statement is complete.

Were it not for one exceptional situation, a local variable could always be regarded as being created when its local variable declaration statement is executed. The exceptional situation involves the switch statement, where it is possible for control to enter a block but bypass execution of a local variable declaration statement. Because of the restrictions imposed by the rules of definite assignment, however, the local variable declared by such a bypassed local variable declaration statement cannot be used before it has been definitely assigned a value by an assignment expression.

The following example contains several different kinds of variables:


						(int count) {			// Complex Expression Block variable
								int x, y;			// x and y are local variables
								int[] w = new int[10];			// w[0] is an array component
						}