It's expected behavior. Your for loop runs once for l=0, since your condition is <=0 because len([]byte{}) is 0.
-- Marcin On Fri, Dec 18, 2020 at 3:28 PM Jochen Voss <jochen.v...@gmail.com> wrote: > Hello, > > I can print slices of bytes as hex strings, using code like the following: > > x := []byte{0, 1, 2, 3} > fmt.Printf("%02x", x[:l]) > > This gives the output "00010203" as expected. But this fails for the > empty slice: running > > x := []byte{} > fmt.Printf("%02x", x[:l]) > > gives "00" instead of the empty string. See > https://play.golang.org/p/rvLLqydDDE6 for a demonstration. > > Is this a bug, or is this expected behaviour? > > All the best, > Jochen > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/bb8774f3-aa17-4044-8435-ed1cd162976cn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/bb8774f3-aa17-4044-8435-ed1cd162976cn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CA%2Bv29LvnU42djCUwRWGokB4YmtCNgeVLzGU7jUJU_BjcAi9KLA%40mail.gmail.com.