Is there a way to iterate over a slice in reverse in Go?

后端 未结 7 1610
猫巷女王i
猫巷女王i 2021-01-30 15:28

It would be convenient to be able to say something like:

for _, element := reverse range mySlice {
        ...
}
相关标签:
7条回答
  • 2021-01-30 16:06

    Variation with index

    for k := range s {
            k = len(s) - 1 - k
            // now k starts from the end
        }
    
    0 讨论(0)
提交回复
热议问题