Chapter 8: declarations, 1 array declarations, Chapter 8 – Teledyne LeCroy SAS_SATA Protocol Suite Verification Script Engine Reference Manual User Manual
Page 32: Declarations, Rray, Eclarations
![background image](/manuals/353604/32/background.png)
32
Chapter 8: Declarations
8.1 Array Declarations
Scripts can declare an array object.
Format:
Array( source, size, default_value )
Parameters
source
(optional) List (collection or stand-alone value) of values to fill array.
size
(optional) Size of array
default_value
(optional) Default value to fill array, if size is greater than size of source.
Examples
set MyArray = Array( [1, 2, 3] );
# Creates an array of 3 elements from list : [1,2,3].
set MyArray = Array( [1, 2, 3, 4, 5, 6] );
# Creates an array of 6 elements from list : [1,2,3,4,5,6 ].
set MyArray = Array( [1, 2, 3, 4, 5, 6], 20, 23 );
# Creates an array of 20 elements. Fills first 6 elements from
# list : [1,2,3,4,5,6 ]. Aftewards, fills remainder with 23.
set MyArray = Array( 64 );
# Creates an array of one element [64].
set MyArray = Array();
# Creates an empty array.
Remarks
Arrays can be iterated using the same syntax as lists (but more efficiently):
for( i = 0; i < sizeof(MyArray); i++ )
{
ReportText( FormatEx( "MyArray[%d] = %d", i, MyArray[ i ] ) );
}
Arrays can use the operators sizeof(), first(), more(), next(), prev(), and last()
.
Therefore, the example array code above can be written:
i = 0;
for( item = first(MyArray); more(MyArray); item = next(MyArray) )
{
ReportText( FormatEx( "MyArray[%d] = %d", i, item ) );
i++;
}