doc: variadic function example (#6093)

pull/6084/head
Maciej Obarski 2020-08-09 04:12:08 +02:00 committed by GitHub
parent 64f218e943
commit 4e8fe9b1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -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