slice2.goΒΆ

// slice2.go

// To run at the command line:
//    $ go run slice2.go

package main

import "fmt"

func main() {
    measurements := []float32{2.3, -0.1, 2, 2.001, 5.5, 5.22}
    n := len(measurements)

    // Print all the values of measurements except for the first and last one.
    fmt.Println("Method 1")
    for i := 1; i < n-1; i++ {
        fmt.Printf("%v\n", measurements[i])
    }

    fmt.Println("\nMethod 2")
    for _, m := range measurements[1 : n-1] {
        fmt.Printf("%v\n", m)
    }
}