mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: index accessor in array init expression (#12181)
This commit is contained in:
@@ -692,6 +692,14 @@ arrays there is a second initialization syntax:
|
||||
```v
|
||||
mut a := []int{len: 10000, cap: 30000, init: 3}
|
||||
```
|
||||
|
||||
You can initialize the array by accessing the it variable as shown here:
|
||||
|
||||
```v
|
||||
mut square := []int{len: 6, init: it * it}
|
||||
// square == [0, 1, 4, 9, 16, 25]
|
||||
```
|
||||
|
||||
This creates an array of 10000 `int` elements that are all initialized with `3`. Memory
|
||||
space is reserved for 30000 elements. The parameters `len`, `cap` and `init` are optional;
|
||||
`len` defaults to `0` and `init` to the default initialization of the element type (`0`
|
||||
|
Reference in New Issue
Block a user