9951 explained code solutions for 126 technologies


golangHow to iterate over a slice in reverse order


package main

func main() {
  arr := []int{10,15,22,34,56}
  for i := len(arr) - 1; i >= 0; i-- {
    // do something with arr[i]
  }
}ctrl + c
package main

default package declaration

func main() {

declare main function that will be launched automatically

[]int{10,15,22,34,56}

sample slice to iterate over

for i := len(arr)

1; i >= 0; i--- iterate overarrin reverse order, starting from last index and ending at0`