Tsallaka zuwa abun ciki
Justice Tech School

Named Returns

Name the results to document them. A bare return sends their current values.

Example
package main

import "fmt"

func stats(a []int) (min, max int) {
	min, max = a[0], a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
		if v > max {
			max = v
		}
	}
	return
}

func main() {
	fmt.Println(stats([]int{3, 1, 2}))
}

Result

1 3

Exercise

Bare return.

Quiz Test

What does a bare return send?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.