0 votes
in GoLang by
What are the looping constructs in Go?

1 Answer

0 votes
by

Go has only one looping construct: the for loop. The for loop has 3 components separated by semicolons:

The Init statement, which is executed before the loop begins. It’s often a variable declaration only visible within the scope of the for loop.

The condition expression, which is evaluated as a Boolean before each iteration to determine if the loop should continue.

The post statement, which is executed at the end of each iteration.

package main

import "fmt"

func main() {

    sum := 0

    for i := 0; i < 10; i++ {

        sum += i

    }

    fmt.Println(sum)

}

Related questions

0 votes
asked Aug 11, 2022 in GoLang by SakshiSharma
0 votes
asked Apr 27, 2023 in GoLang by Robin
0 votes
asked Aug 19, 2022 in GoLang by john ganales
...