for range go
arr = [1,2,3,4]
for i, val := range arr {
print(i, val) // prints iterator, value
}
for range go
arr = [1,2,3,4]
for i, val := range arr {
print(i, val) // prints iterator, value
}
golang iterate through slice
var slice = []string{"Apple", "Orange", "Kiwi"}
for index, sliceItem := range slice { // You can omit index or sliceItem with a _
fmt.Println("Index in slice:", index)
fmt.Println("Fruit:", sliceItem)
}
golang loop
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println(sum)
}
go iterate over slice
nums := []int{2, 3, 4}
sum := 0
for _, num := range nums {
sum += num
}
fmt.Println("sum:", sum)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us