Answers for "go lang how to iterate array with while"

C
0

golang loop through array

arr := []int{1, 2, 3, 4, 5}
//using range 
for index, ele := range arr { // you can escape index by _ keyword
	fmt.Println(index, ele)
}
Posted by: Guest on September-07-2021
0

go Iterating over an array in Golang

package main

import "fmt"

func main() {
    data := [...]string{"Ned", "Edd", "Jon", "Jeor", "Jorah"}
    for i := 0; i < len(data); i++ { //looping from 0 to the length of the array
        fmt.Printf("%d th element of data is %s\n", i, data[i])
    }
}
Posted by: Guest on October-18-2021

Code answers related to "C"

Browse Popular Code Answers by Language