Arrays
You can use arrays in Spice for any primitive or custom struct data type.
Usage¶
To initialize an array
e.g. of type string, you can write:
Spice | |
---|---|
The 3
in the brackets is the size of the array. The initial values can be provided in curly braces after the assign operator and must be of the same data type.
You can only initialize an array with the number of items equal the arrays size or no items.
Type | Default value |
---|---|
int | 0 |
double | 0.0 |
string | "" |
bool | false |
struct | Instance with default values for all fields |
To access an array item, you can use the index. The indexes are >= 0 per definition:
Spice | |
---|---|
More complex expressions for initial array values and item indexing are possible. Here's an example: