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

doc: add section with examples for for k,v in map{} (#6025)

This commit is contained in:
Maciej Obarski 2020-07-31 18:08:12 +02:00 committed by GitHub
parent 1ea511b530
commit fbb260159b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -718,6 +718,30 @@ println(numbers) // [1, 2, 3]
```
When an identifier is just a single underscore, it is ignored.
#### Map `for`
```v
m := {'one':1, 'two':2}
for key, value in m {
println("$key -> $value") // Output: one -> 1
} // two -> 2
```
Either key or value can be ignored by using a single underscore as the identifer.
```v
m := {'one':1, 'two':2}
// iterate over keys
for key, _ in m {
println(key) // Output: one
} // two
// iterate over values
for _, value in m {
println(value) // Output: 1
} // 2
```
#### Range `for`
```v