Go code
names := []string{"Maya", "Noah"}
for index, name := range names {
fmt.Println(index, name)
}Line-by-line explanation
- A slice is created.
- Range visits each item.
- Index and name receive the current pair.
- Both are displayed.
Expected output
0 Maya
1 NoahThis is the expected result.
Use the blank identifier _ when one returned value is not needed.