13.32.7.1 Arrays

An array is another way to group data. Arrays are collections of items stored in variables. Each item has a unique address that you use to access it. You do not need to declare them nor specify their size.

Array elements are handled in the same way as other Tcl variables. You create them with the set command, and you can use the dollar sign ($) for their values.

set myarray(0) "Zero" set myarray(1) "One" set myarray(2) "Two"

for {set i 0} {$i < 3} {incr i 1} {

Output:

Zero One

Two

In the example above, an array called "myarray" is created by the set statement that assigns a value to its first element. The for-loop statement prints out the value stored in each element of the array.