1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

docs: add a mutable iteration example (#9244)

This commit is contained in:
Subhomoy Haldar 2021-03-11 18:23:58 +05:30 committed by GitHub
parent 27cb0d97cc
commit 5ddb2d5b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1147,12 +1147,12 @@ The `for value in arr` form is used for going through elements of an array.
If an index is required, an alternative form `for index, value in arr` can be used.
Note, that the value is read-only.
If you need to modify the array while looping, you have to use indexing:
If you need to modify the array while looping, you need to declare the element as mutable:
```v
mut numbers := [0, 1, 2]
for i, _ in numbers {
numbers[i]++
for mut num in numbers {
num++
}
println(numbers) // [1, 2, 3]
```