Quartus® Prime Pro Edition User Guide: Scripting

ID 683432
Date 7/08/2024
Public
Document Table of Contents

2.9.6. Arrays

Arrays are similar to lists except that they use a string-based index. Tcl arrays are implemented as hash tables. You can create arrays by setting each element individually or with the array set command.

To set an element with an index of Mon to a value of Monday in an array called days, use the following command:

set days(Mon) Monday

The array set command requires a list of index/value pairs. This example sets the array called days:

array set days { Sun Sunday Mon Monday Tue Tuesday\ 
                 Wed Wednesday Thu Thursday Fri Friday Sat Saturday }
set day_abbreviation Mon
puts $days($day_abbreviation)

Use the array names command to get a list of all the indexes in a particular array. The index values are not returned in any specified order. The following example is one way to iterate over all the values in an array.

foreach day [array names days] {
	puts "The abbreviation $day corresponds to the day name $days($day)"
}

Arrays are a very flexible way of storing information in a Tcl script and are a good way to build complex data structures.