go

Organize values in a list format


I know how to do sorting using the command sort.Ints, but the values are shown like this:

[1,2,3,4...]

I would like to organize these values into a list, like this:

1
2
3
4...

Which command should I use to get this result?


Solution

  • Maybe you're looking for something like this?

    package main
    
    import "fmt"
    
    func main() {
        arr := []int{1, 2, 3, 4, 5}
        for _, number := range arr {
            fmt.Println(number)
        }
    }