Answers for "iterate for loop golang"

Go
4

golang loop

package main

import "fmt"

func main() {
	sum := 0
	for i := 0; i < 10; i++ {
		sum += i
	}
	fmt.Println(sum)
}
Posted by: Guest on March-26-2020
0

iterate over iterator golang

func printEvenNumbers(max int) {
    iter := NewEvenNumberIterator(max)
    for iter.Next() {
        fmt.Printf("n: %d\n", iter.Value())
    }
    if iter.Err() != nil {
        log.Fatalf("error: %s\n", iter.Err())
    }
}
Posted by: Guest on February-19-2021

Browse Popular Code Answers by Language