From 4e8fe9b1a829b0e104f996bd03b3d123316393b3 Mon Sep 17 00:00:00 2001 From: Maciej Obarski Date: Sun, 9 Aug 2020 04:12:08 +0200 Subject: [PATCH] doc: variadic function example (#6093) --- doc/docs.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 04f5b4b45b..433b08a801 100644 --- a/doc/docs.md +++ b/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