Selection sort algorithm I am just trying to use Go so I will be thankful for all remarks and corrections:

package main

import "fmt"

func selectionSort(a []int) []int {

    for i := 0; i &lt; len(a); i++ {

        min := i

        for j:= i + 1; j &lt; len(a); j++ {
            if a[j] &lt; a[min] {
                min = j;
            }
        }

        var tmp int = a[i]
        a[i] = a[min]
        a[min] = tmp
    }

    return a
}

func main() {

    values := []int { 5, 8, 4, 1, 7,  2, 3, 6 }
    result := selectionSort(values)
    fmt.Println(result)
}
On Stack Overflow duplicate questions are closed.

For your question, a search of Code Review Stack Exchange for "[go] selection sort" finds, amongst others,

Selection sort algorithm with increasing/decreasing sort options

which has several detailed answers that address your question. For example, the code for my answer, simplified for ascending order only, is

// selectionSort sorts the array a into ascending order.
// The selection sort algorithm is an in-place comparison sort
// with O(n*n) time complexity.
func selectionSort(a []int) {
    for i, x := range a[:len(a)-1] {
        k := i
        for j, y := range a[i+1 : len(a)] {
            if x &gt; y {
                // out of order
                k = i + 1 + j
                x = y
            }
        }
        a[k], a[i] = a[i], x
    }
}


My code is idomatic Go and it's more than twice as fast as your code when running a Go benchmark which sorts 1024 random integers.

BenchmarkDemas           300       4894852 ns/op
BenchmarkPeterSO        1000       2339806 ns/op