I wrote this program,
package main
import "fmt"
func main() {
x := "Hello"
for i := 0; i <= 10; i++ {
fmt.Printf("%#U\n", x[i])
}
}
https://go.dev/play/p/yrMu2hlAvkZ
panic: runtime error: index out of range [5] with length 5
I know the reason why it's giving the error, it's due to the condition in for loop i<=10
and if I remove the =
it will not give me the error.
But let's say I want to code it in such a way that I won't get errors if I still use i<=10
. How can it be done?