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

doc: variadic function example (#6093)

This commit is contained in:
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

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