Skip to content

Instantly share code, notes, and snippets.

@ealipio
Created August 10, 2019 21:18
Show Gist options
  • Save ealipio/12abeaadeb7636da86b2a8c9d52101b8 to your computer and use it in GitHub Desktop.
Save ealipio/12abeaadeb7636da86b2a8c9d52101b8 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
// using the value semantic for of the range
friends := []string{"Annie", "Betty", "Charley", "Doug", "Edward"}
for _, v := range friends {
friends = friends[:2]
fmt.Printf("v[%s] \n", v)
}
// fmt.Printf("Hello, Friends: %v ", friends)
fmt.Println("==============================")
friends = []string{"Annie", "Betty", "Charley", "Doug", "Edward"}
// using the pointer semantics of the for range
for i := range friends {
friends = friends[:2]
fmt.Printf("v[%s] \n", friends[i])
//After prin Betty => panic: runtime error: index out of range
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment