gobyexample/examples/multiple-return-values/multiple-return-values.go
Mark McGranaghan 614bccfeeb less words
2012-10-17 17:25:19 -07:00

31 lines
702 B
Go

// Go has built-in support for _multiple return values_.
// This feature is used often in idiomatic Go, for example
// to return both result and error values from a function.
package main
import "fmt"
// The `(int, int)` in this function signature shows that
// the function returns 2 `int`s.
func vals() (int, int) {
return 3, 7
}
func main() {
// Here we use the 2 different return values from the
// call with _multiple assignment_.
a, b := vals()
fmt.Println(a)
fmt.Println(b)
// If you only want a subset of the returned values,
// use the blank identifier `_`.
_, c := vals()
fmt.Println(c)
}
// todo: named return parameters
// todo: naked returns