doc: variadic function example (#6093)
parent
64f218e943
commit
4e8fe9b1a8
16
doc/docs.md
16
doc/docs.md
|
@ -23,6 +23,7 @@ you can do in V.
|
|||
* [Comments](#comments)
|
||||
* [Functions](#functions)
|
||||
* [Returning multiple values](#returning-multiple-values)
|
||||
* [Variable number of arguments](#variable-number-of-arguments)
|
||||
* [Symbol visibility](#symbol-visibility)
|
||||
* [Variables](#variables)
|
||||
* [Types](#types)
|
||||
|
@ -183,6 +184,21 @@ println(b) // 3
|
|||
c, _ := foo() // ignore values using `_`
|
||||
```
|
||||
|
||||
### Variable number of arguments
|
||||
|
||||
```v
|
||||
fn sum(a ...int) int {
|
||||
mut total := 0
|
||||
for x in a {
|
||||
total += x
|
||||
}
|
||||
return total
|
||||
}
|
||||
println(sum()) // Output: 0
|
||||
println(sum(1)) // 1
|
||||
println(sum(2,3)) // 5
|
||||
```
|
||||
|
||||
## Symbol visibility
|
||||
|
||||
```v
|
||||
|
|
Loading…
Reference in New Issue