How to Iterate Over a String in Go with range

Iterate over a Go string using a for loop with range to access indices and runes.

Use a for loop with the range keyword to iterate over a string, which yields the index and the rune at each position.

s := "hello"
for i, r := range s {
	fmt.Printf("Index: %d, Rune: %c\n", i, r)
}

If you only need the runes and not the indices, use _ to discard the index variable.