Created
August 10, 2019 21:18
-
-
Save ealipio/12abeaadeb7636da86b2a8c9d52101b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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